Reputation: 325
Hi i'm newbie in Laravel just practicing with some tutorial videos and i'm wondering if it is possible to configure the brackets position when i use the artisan commands.
For example when i create new controller using artisan make:controller it makes
class Controller extends Controller
{
//
}
What i want is the brackets places right next to the class declaration not in the new line like above. To be more specific
Class Controller extends Controller{
//
}
This is what i want. Is it possible to configure the brackets position?
I've googled a lot and read documentation but couldn't find any of information about it.
--Edited--
Thanks to you guys i know it's not Laravel problem and it can be configured in code editor.
I'm using vs code and have installed several php formatter but it seems all of them follow the PSR-2 styles.
I found JS configuration for its brackets position but couldn't find for PHP i know it's not even problem i just don't like this format
Upvotes: 2
Views: 738
Reputation: 35200
As mentioned in the comments, the stubs that Laravel generates follow PSR-2 so making this change would break that.
To override the controller code that Laravel generates with make:controller
you're going to have to override the ControllerMakeCommand
and copy the default stubs you want to edit.
The stubs for this command have changed quite a bit with the different versions of Laravel so it will require a bit of copy and paste to ensure it works correctly.
Extend the ControllerMakeCommand
Inside your app/Console/Commands
directory create ControllerMakeCommand.php
and add the following:
<?php
namespace App\Console\Commands;
use Illuminate\Routing\Console\ControllerMakeCommand as BaseCommand;
class ControllerMakeCommand extends BaseCommand
{
//
}
Add the getStub
method
Find the getStub()
method in the Illuminate\Routing\Console\ControllerMakeCommand
and copy that into your newly created ControllerMakeCommand
.
Copy the default stubs
Copy
vendor/laravel/framework/src/Illuminate/Routing/Console/stubs
to
App/Console/Commands/stubs
(you don't have to copy all of the files inside it, just the controller.*
that you want to override).
Change the formatting of the files as you see fit.
Laravel <=5.4
If you're using Laravel <=5.4 commands are not automatically loaded for you so you're going to have to tell Laravel that you want to use this command.
In your App\Console\Kernel.php
add your new class to the $commands
array e.g.:
protected $commands = [
\App\Console\Commands\ControllerMakeCommand::class
];
NB Obviously, feel free to store the stubs wherever you want just make sure you update the paths in your new ControllerMakeCommand
.
Upvotes: 1