Posts by Pedro Sanção • 5,639 points
147 posts
-
0
votes2
answers81
viewsA: Add data from "pivot" table of relation Many to Many
In Laravel 7 or earlier there is no simplified form of the framework to make this query, but using Eloquent it is possible to do as follows: class Cliente extends Model { public function…
-
1
votes2
answers18
viewsA: How to fix redirecting to subdomains that are on different servers?
The Laravel has several helpers to avoid sending HTTP headers manually. For redirecting you can use the function redirect (attention to return): Route::any('/', function() { return…
laravelanswered Pedro Sanção 5,639 -
3
votes2
answers52
viewsA: Call and apply methods in functional composition
The name of this resource is composition and is used mainly in functional programming, I did not find an article in Portuguese, in English has the article Function Composition on Wikipedia.…
-
2
votes3
answers104
viewsA: How does inheritance work with "Constructor Property Promotion" in PHP 8?
I set up an environment with PHP 8 and performed some experiments and discovered the following. Define the visibility (public, protected, private) of the arguments in the class constructor generates…
-
4
votes2
answers135
viewsA: Is it possible to delete previous commits and only remain the current one?
I would like to propose one more option besides those described by hkotsubo: redo the commit rebase interactive with squash merge with squash To make the merge with squash I will demonstrate by…
-
2
votes3
answers104
viewsQ: How does inheritance work with "Constructor Property Promotion" in PHP 8?
PHP 8 now supports constructor Property Promotion to declare class properties in constructor arguments: class Foo { public function __construct( public $foo, ){} } By making the inheritance by…
-
-2
votes1
answer111
viewsQ: What defines an attribute class in PHP 8?
I am using PHP 8 attributes, the documentation of this feature is still rudimentary, it only contains code examples and the api is not documented so I am experiencing the use of the resource. class…
-
0
votes1
answer111
viewsA: What defines an attribute class in PHP 8?
TD; DR: To define an add class attribute class #[Attribute] before class: namespace App; use Attribute; #[Attribute] class MeuAtributo {} The use is necessary only when the class uses namespace, as…
-
0
votes1
answer32
viewsQ: How to access PHP 8 attributes (or Annotations)?
I’m experimenting with the attributes (or Annotations) PHP 8. I created some sample classes and added the class, property and method attributes. <?php #[Attribute] class ClassAttribute {}…
-
0
votes1
answer32
viewsA: How to access PHP 8 attributes (or Annotations)?
You can access class, property and method attributes using the method getAttributes() (not yet documented) respectively of the classes ReflectionClass, ReflectionProperty and ReflectionMethod:…
-
0
votes2
answers152
viewsA: Query between Mysql dates showing all days of range
Old question but currently there is a more elegant solution supported from Mysql version 8, using a common table Expression (clause WITH) recursive. WITH RECURSIVE cte_count (n) AS ( SELECT 1 UNION…
mysqlanswered Pedro Sanção 5,639 -
0
votes1
answer42
viewsA: How to make MYSQL SELECT "create" the days you don’t have in the table
From Mysql version 8 is possible with a common table Expression (clause WITH) recursive. I isolated only the stretch to popular the days between 1 and 30, from there can do the Join with the rest of…
-
0
votes1
answer33
viewsA: In PHP using datetime.format what is the meaning of %a
The complete table is on that other page of the documentation. %a represents the period of the day with "am" or "pm" and is useful when displaying hours in the 12-hour format with %h.…
-
0
votes2
answers61
viewsA: Execute method only if there is specific property in the object. No testing each line with hasOwnProperty() or comparing with Undefined
Instead of changing the calls I suggest changing the approach and making the change in the definition of methods preenche... to check if a value has been passed: preencheIdade(idade) { if (!idade) {…
javascriptanswered Pedro Sanção 5,639 -
0
votes2
answers123
viewsA: How to disable a branch on Github?
The command to delete a remote branch is push. How the branch parameter can use the : to use different names for the local and remote branch, it is also possible to delete. git push origin…
-
1
votes2
answers64
viewsA: Removing dynamic rowspan lines in table
To do this, you need to perform 3 steps: Identify the selected radio Get indices for the parent element of each row Remove the lines The code would stand: var radio =…
-
1
votes1
answer121
viewsA: How to generate two pages with DOMPDF in Laravel
Based on users' Soen responses cotton and Brians: DOMPDF handles paging automatically. If you want to force a page break you can use the CSS style page-break-before: always; or page-break-after:…
-
0
votes1
answer139
viewsA: Working with Images - PHP
What errors, obtained by $_FILES['image']['error'] still keeps the file on the server? Only when the value of the key 'error' is 0 (or the constant UPLOAD_ERR_OK) the file will be kept in 'tmp_name'…
-
1
votes1
answer21
viewsA: Laravel: Display Row() instead of result()
You can use the method pluck() <?php DB::table('...') // ... ->pluck('id'); P.S.: with Laravel it is recommended to have a Model for each table, so you do not need to pass the table name in…
-
1
votes1
answer629
viewsA: Param Bind with Array - PHP and Mysqli
There is no bind of array, you need to place all question points dynamically, one for each item of the array: $clientes = [2, 15, 78, 93]; $queryParameters = join(',', array_fill(0,…
-
1
votes2
answers87
viewsA: How to authenticate a user when the "username" field receives values that can reference different columns in the database table?
I needed to customize a login query in a work project and figured out how to do it. The process is undocumented and needs to read enough code to understand in detail how it works. The solution is…
laravelanswered Pedro Sanção 5,639 -
1
votes1
answer45
viewsA: Collection:::Orders does not exist - Laravel
This error happens because you are trying to execute the method of Model in a Collection, the method all() returns a collection (which can be understood as an array) of Models. To load the relations…
-
0
votes1
answer120
viewsA: Make an encrypted Mysql database connection
The most common is to use environment variables to store database connection credentials. The file pattern is widely used .env (dotenv or "dot env") to write environment variables. And to read these…
-
0
votes2
answers247
viewsA: Middleware in the Laravel to check if the user belongs to a group
You can add a parameter in middleware as documented: public function handle($request, Closure $next, $setorPermitido) { if ( !auth()->check() ) return redirect()->route('login'); $setor =…
-
1
votes3
answers1776
viewsA: Deselect radio type input
I created a snippet and share here: // itera com método do Array para compatibilidade Array.prototype.forEach.call(document.querySelectorAll('[type=radio]'), function(radio) {…
-
1
votes3
answers163
viewsA: PHP - How to make sure that if a POST is not entered, it does not appear "Notice: Undefined index"
Use the function filter_input, she gets a constant INPUT_GET or INPUT_POST: <?php echo filter_input(FILTER_POST, 'email'); this function also allows you to apply filters on the variable read, see…
phpanswered Pedro Sanção 5,639 -
4
votes1
answer625
viewsA: What is the purpose of git update-index?
The command update-index updates the GIT index, the main use is to consider modified files as unmodified with the parameter --assume-unchanged. Another important parameter is the…
gitanswered Pedro Sanção 5,639 -
0
votes3
answers566
viewsA: show all options of <select> without scroll bar
Apply CSS styles to <select> is a rather complicated task because each browser renders in a different way, and I believe that there is no way to control the size of the dropdown native. If you…
-
1
votes2
answers1100
viewsA: GIT - "import" content from another branch
To "transfer" the branches simply rename. To import another repository as a branch, add the remote repository, do checkout and delete the remote: # renomeia master (atual) para bootstrapv4 git…
-
2
votes1
answer1073
viewsA: Calculate formatted input (mask)
The library you use has the method .maskMoney('unmasked') to extract the value as float, that you can use to calculate the total. $(function(){ var valor = $('#valor'); var quantidade =…
-
3
votes2
answers492
viewsA: PHP security failure
This is an invasion attempt that is worth a PHP vulnerability in CGI mode where php-cgi receives the query string as command line arguments, allowing options to be included via URL. By decoding the…
-
0
votes2
answers697
viewsA: Automatic menu break with icon and text aligned
I got the image effect by changing only one CSS rule (include here only what I modified): #nav-root > li > a .menu-icon { display: block; margin: auto; } .container { max-width: 1100px;…
-
4
votes4
answers118
viewsA: Working with Array and selecting a specific Input
Use the property HTMLSelectElement.selectedIndex as a function argument .eq() to select the <input> by index. $('[name=options]').bind('change', function(){ $('.input').hide() // ocultar todos…
-
0
votes3
answers186
viewsA: Use interfaces to abstract connection type
I suggest only an improvement in class Fabrica, use class constants: class Fabrica { const TIPO_MYSQL = 'MySQL'; const TIPO_MSSQL = 'MSSQL'; public function fabricar($banco = self::TIPO_MYSQL) {…
-
2
votes3
answers341
viewsA: CSS condition for when you don’t have SRC in the image
Use a attribute selector, and the pseudo-class :not(): img { width: 150px; height: 150px; } .no-src { background-color: #00f; } .empty-src { background-color: #0f0; } img[src=""], img:not([src]) {…
-
1
votes3
answers1977
viewsA: How to attach events to dynamically created elements and pass parameters?
Using your workaround is possible. These ID’s can be added with a type attribute data-* where * should be replaced by a. Modify the Javascript that generates the link to: return '<a href="#"…
-
1
votes1
answer156
viewsA: Error Creating mysqli connection
The error happens because the extension mysqli is not enabled. The phpinfo() that you should seek is Mysqli Support enabled. Recent Linux versions of the Debian family (such as Ubuntu) have a…
-
1
votes2
answers588
viewsA: Automatically select text
For this answer I will consider only the browsers that follow the default, so it will not work in IE (maybe adapting the method used in the first if of the code in the question). In order to select…
-
6
votes4
answers2145
viewsA: What technique do I use to keep a form field completed or selected after $_POST[]?
I consider to this answer that you want the values "selected after giving a $_POST in the form", therefore it is not necessary to keep this data in the session, only on the page submitted by the…
-
5
votes3
answers155
viewsA: Why is 'getattribute()' not a function?
Because getElementsByTagName() returns a HTMLCollection (who behaves like a array), then you need to access as a array: link[0].getAttribute('id'). Another problem is that .getElementsByTagName('g…
javascriptanswered Pedro Sanção 5,639 -
8
votes3
answers596
viewsA: What is the difference between DOM event handlers?
The @Edilson response has a theoretical approach, I will try to explain in practice the differences. Add event handlers (Event handlers) with html attribute or with the estates .on* has the…
-
3
votes3
answers3683
viewsA: Run Javascript in the URL(plugins.)
The name of this resource is bookmarklet and does not depend on plugins to work. According to Wikipedia: A bookmarklet is a small Javascript program that is stored as a URL in Bookmarks. The…
-
4
votes2
answers66
viewsA: Right way to get a certain div
Combine the function .parents() with the selector :eq(): $("#conteudo").parents(':eq(2)') Note that indexing is at 0, so to access the 3rd level should be used 2.…
jqueryanswered Pedro Sanção 5,639 -
0
votes2
answers235
viewsA: header Content-Type does not let you use HTML/CSS
When you send a header Content-type you cannot use more than one file type (image and HTML, in your example). One solution is to encode the generated image on base-64 and display with a data URI,…
-
1
votes3
answers4206
viewsA: Catch callbacks from an ajax
Short answer: there is no native method. The function jQuery.ajax() returns an object that implements the interface Promise, which allows only the assignment of callbacks. This interface is…
-
3
votes2
answers378
viewsA: Separate string from end to start with substr php
If I understand correctly you want "the whole string minus the last 7 characters". According to the documentation: If length [the third parameter] is given and is negative, then this amount of…
phpanswered Pedro Sanção 5,639 -
2
votes1
answer40
viewsA: If you have this character, discard the capture
In the comment of @Viníciusgobboa.deOliveira was used a Egative lookbehind assertion (?<! subexpression) to check the previous character. PCRE and . NET syntax is the same. (?<!\\)(\}) It…
-
1
votes3
answers43
viewsA: Name a csv file
For lists the files exist more than one way, as pointed out in the other answers. Either way you will have to extract from the name the portion that refers to date, by position or with regular…
phpanswered Pedro Sanção 5,639 -
2
votes2
answers351
viewsA: Is it possible to use $this with static methods?
What do you call hack is actually a design pattern (Pattern design) called Singleton: This pattern ensures the existence of only one instance of a class while maintaining a global access point to…
-
2
votes2
answers797
viewsA: case and minuscule differences in the URL
You can easily do the apache ignore the cashier using the module mod_speling, which is part of the standard modules but needs to be activated. Activate the module, restart the apache and add to…