Change php artisan make:controller resource layout - php

When we use
php artisan make:controller --resource
a controller with basic functions is created.
I want to change this code to add more functions that all controllers will use.
How to change the default resource code?

Thank's to #teeyo I was able to make a new search and found this:
https://blog.vigilantmedia.com/2015/08/07/how-to-customize-controllers-generated-by-artisan-in-laravel/

Related

Laravel artisan make:component outside resources folder

When you run php artisan make:component Foo it will always be created inside (root)/resources/views/component.
How can I specify its "parent directory" or any specific directory outside resources folder?
I mean, like creating it at (root)/custom-package/components.
Is there any existing options does make:component command has? or I'm thinking few ways how to achieve this:
Create a custom command that will create the php and blade files to the directory I want.
Create a new command and extend the Laravel's make:component command to modify its path. (Currently, I can't find yet the Class where I can extend it.)
Or is there a config where I can set it?
maybe you can use:
php artisan make:component Foo --path=your/custom/location
hope this help

What does the "--resource" mean by make controller command in Laravel?

I was using make controller command in Laravel. However, I did not understand the extension like --resource, --resource --model=Photo etc.
php artisan make:controller PhotoController --resource
With --resource you will get controller with index, create, store, show, edit, update, destroy methods and with --model you will bind that class into this methods

Laravel Controller not adding to route list

I created a new controller with resources using the PHP artisan command:
php artisan make:controller AdminCategoriesController --resource
The file gets added to the controller folder but when I visit my route list with I see no route about it:
php artisan route:list
Here my routes list:
How can I add the categories to my routing list?
This error is showing because you did not give instance of Resource Controller in web.php file.
Route::resource('route','AdminCategoriesController ');
When you did this , route list will show.
I failed to add the route resource in my routes.php
Route::resource('/admin/categories', 'AdminCategoriesController');
Everything works now.
If you are using api then use this syntax to generate controller
php artisan make:controller API/PhotoController --api

php artisan make:controller Command not working in Laravel 5.3 Moduler App

I am working on a Module App in Laravel 5.3. I have setup module and It is working nice. My App directory structure is as below:
App
|
|_Http
|
|_Modules
|_SMS
|_Controllers
|_Models
|_Views
My question is, how I can make a controller in Modules/SMS/Controller folder from command line? I tried "php artisan make:controller App/Modules/SMS/Controller/Api/V1/UserController". But controller create in Http/Controller/Api/V1 directory. That is default Controller Directory. Thanks in Advance
You need to give the path in which you have to create the controller
php artisan make:controller pathName/controllerName
This will create controller in app/Http/Controller/YourPath/Controller
To Create it in Some Other Directory You need to do as Follows Inside app/Providers/RouteServiceProvider
Give Your New Default path in $namespace
protected $namespace = 'App\Http\Controllers';
//to
protected $namespace = 'New Default Path'
If you keep $namespace Blank Then every time you create controller You will have to give the path
Try This. Hope it works
You only need to pass the name of the subdirectory like this:
php artisan make:controller subDriectory/YourController
php artisan make:controller subDriectory/YourController --plain
Please try it and see if it works :)

Create model in a custom path in laravel

I want to create a model in a custom path. If i write the php artisan command like the following it will create model inside app.
php artisan make:model core
But i want to create the model file inside the custom made Models folder. How can i do it ?
Just define the path where you want to create model.
php artisan make:model <directory_name>/<model_name>
e.g.
php artisan make:model Models/core
You can do it easily with custom directory of your Models Folder (I assume Models Folder is sub folder of App).
Just use this command php artisan make:model Models/core then you will get your desire result.
Thanks.

Categories