I am new to Laravel 5 and gone through https://laravel.com/docs/5.8/controllers but could not find any way in which i could create controller using php artisan with a specific method name. I tried below options but none of them work.
php artisan make:controller HomeControler#index logout
and
php artisan make:controller HomeControler/index logout
and
php artisan make:controller HomeController index logout
Is it possible in Laravel 5 to achieve this? If yes, is it also possible to declare more than one function while creating controller using artisan make command?
php artisan make:controller HomeControler --resource
The controller will contain a method for each of the available resource operations:
index
create
store
show
edit
update
destroy
You can't generate Controller and specified the name of method which will be generate. The only way to generated controller with all CRUD methods It is when you generate a resource based controller
php artisan make:controller PersonController --resource
The other way is to generate Controller which is empty
Related
I am new in Laravel and I want to create a model with all it's basic properties like fillable, table etc. using artisan.
I have explored some blogs but I have not found any way to create a model with basic fields. So, Is there any command to do it like we can do it in CodeIgniter 4?
There is no automatic way to create table fields using artisan, what you can do instead is create the following and modify it:
php artisan make:model Blog -mcr
Read more on model options: https://laravel.com/docs/9.x/eloquent#generating-model-classes
The above will create:
A model named "blog"
A migration file - this is where you can modify/add fields to the database
A resource controller named "BlogController"
For migrations, you need to edit your migration file that it generated, see the documentation on how to do this: https://laravel.com/docs/9.x/migrations#migration-structure
Once you finish you can run the command:
php artisan migrate
to push the changes of the migration file to the database.
Alternatively, you can always see what kind of options you have in artisan by doing:
php artisan make:model -help
And if you want to create everything related to the model, do the command:
php artisan make:model Blog -a
Generate a migration, seeder, factory, policy, resource controller,
and form request classes for the model
i am using this
php artisan make:model Category -mcr`
Its fine but i want this resource controller
with model parameter in different folder.
Thank you for help/suggestions.
In Laravel, what's the difference between a regular controller and resource controller? Please provide examples to illustrate the differences.
There is mainly no difference..It a special type of controller.
When you create a controller like this
php artisan make:controller YourNameController --resource
it auto create some function like index, create, store, show, edit, update, destroy. basically for crud.
For details go to documentation https://laravel.com/docs/7.x/controllers#resource-controllers
Well, the only difference is this.
The resource controller creates a PHP file with already defined CRUD operations while a regular controller creates an empty file.
To create a regular controller with the name UserController
php artisan make:controller UserController
To create a resource controller
php artisan make:controller UserController --resource
Hope it was helpful
Use this for more resources https://laravel.com/docs/9.x/controllers
I am working on a php laravel webapp.
I am creating models for my database.
I have to write models class and migrations too.
Is there a way to only write model class and generate migration class automatically
?
Artisan is not able to detect changes in Model class ?
Thanks
You can simply generate Model with using
php artisan make:model model-name -m
parameter -m stands for auto create migration while you are creating model.
I was working on a PHP application and at some point needed to include a login. I did that by running php artisan make:auth to generate the authentication files. Later on I realized that my HomeController was not the same again. It only contained one function as opposed to my own HomeController which had multiple functions.
Is it possible to retrieve my HomeController?