Ejemplo 1: ejecutar el comando artisan desde el controlador
If you have simple job to do you can do it from route file.
For example you want to clear cache. In terminal it would be php artisan
cache:clear In route file that would be:
Artisan::call('cache:clear');
Ejemplo 2: hacer un controlador de modelo con un solo comando
# to make only Model Class
php artisan make:model Customer
# to make resource controller
php artisan make:controller CustomersController --resource
# make controller for already existing Model Class (binded to model)
php artisan make:controller CustomersController --model=Customer
# to make model, migration and controller all in one command
php artisan make:model User -mcr
# here m for migration, c for controller, r for resource methods in controller
Ejemplo 3: use el comando php artisan a través del controlador
<?php
Route::get('/foo', function () {
Artisan::queue('email:send', [
'user' => 1, '--queue' => 'default'
]);
//
});
Ejemplo 4: crear modelo, controlador y migración en un solo comando laravel
php artisan make:model Products -mcr
-m, --migration Create a new migration file for the model.
-c, --controller Create a new controller for the model.
-r, --resource Indicates if the generated controller should be a resource controller
newer versions of laravel > 5.6
php artisan make:model Products -a
-a, --all Generate a migration, factory, and resource controller for the model
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)