Posts by Wallace Maxters • 102,340 points
1,984 posts
-
21
votes6
answers1578
viewsQ: Is it good practice to use constructors (or magic methods) in interfaces?
Well, I usually come using interfaces to define how some methods will be used. But to be honest, I’ve never seen anyone using interfaces to define contracts for a construtor. In a specific case I…
-
3
votes1
answer1351
viewsA: How to display the previous navigation url with PHP?
Perhaps the solution is a very simple thing, as in the case below, using $_SERVER['HTTP_REFERER'] <?php if (isset($_SERVER['HTTP_REFERER'])): ?> <a href="<?php echo…
-
4
votes1
answer246
viewsA: Is there any way to configure Laravel 4 to use namespaces?
Composer and his magicians It is possible yes, but already adding that to do this you must be used to working with the Composer. Let’s take the necessary steps: 1 . Add namespaces to each file in…
-
5
votes1
answer11573
viewsQ: What is the difference between normal dump-autoload and optimized dump-autoload in Composer?
In the Poser it is possible to automatically generate autoload using the command composer dump-autoload. But it is also possible to generate an "optimized autoload" through the command composer…
commiserateasked Wallace Maxters 102,340 -
2
votes1
answer246
viewsQ: Is there any way to configure Laravel 4 to use namespaces?
In the Laravel 5, I noticed that they have now added namespaces in the application folder. But things weren’t like that in the version Laravel 4. In the Laravel 5, for example the Controllers would…
-
9
votes1
answer388
viewsQ: How do I create a home page for my GITHUB libraries?
Usually, when we activate the github page for a particular package, a url is generated for you to publish documentation regarding a particular library in the Github. In case if my account is called…
githubasked Wallace Maxters 102,340 -
11
votes1
answer388
viewsA: How do I create a home page for my GITHUB libraries?
Github Pages You’re talking about the Github Pages. On Github, you can create the home page (at the domain root) of your account. You should pay close attention because you need to do this operation…
githubanswered Wallace Maxters 102,340 -
0
votes2
answers1625
viewsQ: How to know the current route on Laravel 4?
In Laravel 5, we can take the current route (I mean the class instance) using the class Illuminate\Http\Request, through the method route. Thus: public function handle(Request $request) { $rota =…
-
3
votes1
answer344
viewsA: Difficulties in Route Creation and Laravel Controller 5.1
To create CRUD with controllers, I suggest you use the method Route::resouce. It is quite simple, and you just need to have a controller with the following methods: (get) index (get) edit (post)…
-
0
votes1
answer27
viewsA: Laravel accessors does not work with field separated by _ with a letter
There is a misinformation in the question: The access methods of Laravel do not require parameter. Example: public function getEnderecoCAttribute() { return 'Endereço C'; } And I also did the tests…
laravel-4answered Wallace Maxters 102,340 -
4
votes1
answer475
viewsQ: What is the difference between array_replace and array_merge?
I wonder what the difference is between array_replace and array_merge, because in some cases the two seem to have similar behaviors. Example: $informacoes = ['nome' => 'wallace', 'idade' =>…
-
3
votes1
answer369
viewsQ: When my class returns a modified new instance of the class itself instead of modifying it itself, is it a project pattern?
I’m developing a class that is a collection of values. In it I have several methods that filter the values contained in this collection. My intention is to return a new instance of this same class…
-
3
votes1
answer236
viewsQ: What is the difference between __CLASS__ and get_called_class?
In PHP, I know two methods to display the name of the current class being called: through the magic constant __CLASS__ and function get_called_class(). Apparently, they both do the same thing. class…
-
3
votes1
answer196
viewsQ: How does callback sort functions work internally?
In php, when we want to order a array in a customised way we can use the function usort. I know that for this function to work, we must use values 1, 0 and -1. In case, if I wanted to order this…
-
2
votes3
answers779
viewsA: Is there any way to make asynchronous PHP url requests?
Just as a complement to the @Viniciuszaramella response, where he quotes the requisitions from Guzzle\Http. Explanation of the Asymchronism of the Guzzle Regarding the asynchrony regarding Guzzle…
phpanswered Wallace Maxters 102,340 -
2
votes3
answers779
viewsQ: Is there any way to make asynchronous PHP url requests?
I need to make several requests (about 200 requests) for an external url, but I don’t want php to "wait" for the request to end. Remembering that I want to avoid using functions like exec and things…
phpasked Wallace Maxters 102,340 -
1
votes1
answer513
viewsQ: How do I run Artisan in a specific environment?
How can I perform the Artisan as a specific environment? 'Cause when I spin php artisan tinker It is generating an error because it is recognizing the configuration of the production database. But I…
-
1
votes1
answer513
viewsA: How do I run Artisan in a specific environment?
This can be solved very simply. Just use the option --env=nome_do_ambiente to make the artisan recognise another environment. Example: php artisan tinker --env=local This makes the artisan capture…
-
0
votes2
answers325
viewsA: How can I execute this query with Laravel 5?
You have to create the models referring to the tables. class Anuncio { protected $table = 'anuncios'; } class Categoria { protected $table = 'categorias'; } Then create the relationship in Anuncio…
-
1
votes1
answer5223
viewsQ: What is the Xarg command for?
What is the command for xargs? For example, I’ve seen examples ls pasta/ | xargs -l git update-index I saw that this was being used because the command git update-index does not work with folders.…
-
3
votes1
answer625
viewsQ: What is the purpose of git update-index?
I was facing issues with folders, which should have been ignored in the repository, but they weren’t even when I put in .gitignore, and I’ve done a lot of research to solve the problem. Among…
gitasked Wallace Maxters 102,340 -
9
votes3
answers247
viewsQ: What is "One Level of indentation"?
I was watching this the other day video lesson on Laracasts, where there is an explanation that teaches to avoid accumulating too much code in one method, separating into several methods with…
terminologyasked Wallace Maxters 102,340 -
0
votes1
answer527
viewsQ: How to do a period limited search with datepicker?
I have a field data_inicio and a field data_fim. I need to use the datepicker both of us. I want that when I select the date data_inicio, the field data_fim is affected, so that only later dates of…
-
0
votes2
answers1331
viewsA: HTTPS server consults postal zip code
Silvão, cool? Since you’re using Laravel, how about using a Proxinig? It will work as follows: You grab send a request to the zip url by Laravel, and by jQuery, you send the request to the Laravel.…
-
11
votes1
answer2988
viewsQ: What is the purpose of the "/dev/null" path in some commands?
Many times, I have seen some people teaching to do some commands (mainly related to text outputs or things like), where is used this directory or file called /dev/null. Example: wget -qO- $url…
linuxasked Wallace Maxters 102,340 -
6
votes1
answer787
viewsQ: How to find out if a directory is empty by the terminal?
I sent some files, via ftp, to put my application into production. Due to some error occurred in the application, I realized that some files were missing. When I gave a ls I realized that some…
-
8
votes3
answers6502
viewsA: How to install Composer globally on linux?
The solution to this is just to move the downloaded file to the folder /usr/local/bin. Come on. 1) First download the Composer file: curl -sS https://getcomposer.org/installer | php 2) I believe…
-
4
votes3
answers6502
viewsQ: How to install Composer globally on linux?
Usually, when we install Composer, I usually do so: curl -sS https://getcomposer.org/installer | php It downloads a file called composer.phar. But then I have to keep putting the path of the folder…
-
3
votes3
answers6726
viewsA: Return to Previous Page when Error
I think the best way would be using PHP. if ($email === '') { header('location: /index.php'); exit; } Remembering that, to use this form, it is necessary that no content is sent to the browser, by…
-
2
votes2
answers83
viewsA: Take All Records and Separate by Status
Thinking quickly here, I can do this by separating into two queries. $dealer = Dealer::find($id); $medalhas_que_tem = $dealer->dealer_medalhas()->get(); $medalhas_nao_tem =…
-
3
votes2
answers346
viewsQ: Standard Laravel Input Value
In the Laravel, I want that when a certain value does not exist in the Input, i can set a default value. With pure PHP, it is possible to do so: $text = isset($_POST['text']) ? $_POST['text'] :…
-
3
votes1
answer635
viewsA: How to customize the return of an attribute in Laravel?
You need to define an attribute using a Laravel called Eloquent Accessor, in which you define the field name by placing get at the beginning and attribute in the end. Are the so-called Model…
-
3
votes1
answer635
viewsQ: How to customize the return of an attribute in Laravel?
In the Laravel, i know that attributes can return an object of type Carbon\Carbon (an extension of DateTime php), if the field is created_at or updated_at. Example: $usuario = Usuario::find(1); //…
-
1
votes3
answers201
viewsQ: Is making queries in a view, in the MVC standard, a bad practice?
I know that most PHP frameworks are used by default MVC. Where thing guy (theoretically) should stay in his particular place. For example, the controllers are responsible for the request and other…
-
3
votes1
answer849
viewsA: Laravel - Return HTML or JSON in the same Method
My solution to this would be to detect the header of the requisition. If required XHTTPRequest, we return JSON. If not, we return HTML. Think of this idea: Route::get('usuarios/listar', function…
-
1
votes1
answer694
viewsA: Git init did not create branch master
It seems that when you have just created a repository it is common. I did some tests here and only the branch appears when I did the following: git init touch um_arquivo_incial git add…
gitanswered Wallace Maxters 102,340 -
3
votes2
answers11548
viewsQ: How to remove unused packages in the node_modules folder with the NPM command?
I installed some packages from NodeJS via npm install. But then I decided to remove some. Even when I install again, the folders of the packages I’m not using remain there. In the composer PHP, when…
-
1
votes1
answer53
viewsQ: How to use Bower to install from a bitbucket repository
Here at the company where I work, we have some libraries that we develop specifically for the company. That’s why I’m using bitbucket, with a private repository. How can I do to install via bower, a…
-
2
votes1
answer405
viewsA: How to validate login without redirecting the page?
Come on. I believe that the best solution in your case to not redirect the page if there is an authentication error is to use ajax, because from what I understand you are using a dropdown. You can…
-
3
votes1
answer1419
viewsA: How to add my validation in Laravel Validator?
Yes, in the Laravel you can add your own validation. In the Laravel 4, just add the following code to the file app/start/global.php: Validator::extend('telefone-com-ddd', function ($attributes,…
-
2
votes1
answer84
viewsQ: Regarding jQuery functions, is it risky to use them in inline elements?
There’s a good question here at Stackoverlow that talks about the practice question Because it is bad practice to use Javascript inline? But now, not wanting to look at the issue of bad or good…
jqueryasked Wallace Maxters 102,340 -
5
votes3
answers1419
viewsQ: What is the difference in checking an array with isset and array_key_exists?
In PHP we often have more than one way to do the same operation. A basic example is in verifying the existence of a given index in a array: we can use array_keys_exists. Example: $arr = ['a' =>…
-
1
votes1
answer1419
viewsQ: How to add my validation in Laravel Validator?
In the Laravel, both the 4 and the 5, we have the class Validator, which allows specific validations to be made. By default there are several, such as required, email, same and others. But I would…
-
4
votes2
answers1138
viewsA: Present summary content in Laravel 5.1
In the Laravel there is a resource that allows us to return a value, in a model property, as if it were in the table. For example, if you have the field conteudo in your table, you will be able to…
-
6
votes2
answers86
viewsQ: Is it safe to use Javascript’s String.Concat method in current browsers?
I was observing that in Javascript the object String has a method called concat. Serves to do the same thing as the operator + ago. "Meu nome é " + nome Already with concat would look like this:…
-
1
votes4
answers173
viewsA: Javascript PHP sprintf equivalent
My solution to this would be to add a method to prototype of String: String.prototype.format = function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function(text, key) { return…
-
4
votes3
answers1261
viewsA: Self Relationship with Laravel
Maybe what you’re trying to do is use the nested relationship. It is a way to bring, through the method with, a relationship relationship. Example: posts relates to usuários, and each user has one…
-
0
votes2
answers1011
viewsA: How to Accumulate strings in a single variable?
In PHP there are two changes. You can accumulate with a array. Example: $acumula = []; for ($i = 0; $i < 10; $i++) { $acumula[] = $i; } Upshot: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, ] Or with a…
-
2
votes2
answers28028
viewsA: How to make a horizontal line responsive?
Wouldn’t it be better to use the HR to do this? hr{ border-color:#aaa; box-sizing:border-box; width:100%; } <hr/> If necessary, just format it the way you want, so that it will look amazing…
-
40
votes6
answers2300
viewsQ: AJAX is not a programming language. So what is it?
I’m asking this question because I’m tired of seeing things as requirements for a certain programming position: You need to know the languages PHP, Javascript, CSS and AJAX I have learned that AJAX…