Procédure
php artisan is the command line interface included with Laravel. It provides many useful commands for developing and managing a Laravel application. Here is a guide to some of the most common artisan commands and how to use them.
Before reading this documentation, we invite you to access your hosting's Web Terminal.
To see all the commands available in Laravel :
php artisan listTo start the integrated development server :
php artisan serveStarts a local development server to run your Laravel application.
By default, the server starts on http://localhost:8000. You can specify a different port:
php artisan serve --port=8080Migrations are used to manage the database structure.
Creating a new migration:
php artisan make:migration create_users_tableRun migrations:
php artisan migrateExecutes the database migrations and updates the database schema.
Undo the last migration:
php artisan migrate:rollbackTemplates are used to interact with the database tables.
Create a new model:
php artisan make:model UserCreate a model with a migration, a controller and a factory:
php artisan make:model User -mcrControllers manage the logic of the application.
Create a new controller:
php artisan make:controller UserControllerCreate a resource controller:
php artisan make:controller UserController --resourceViews manage the presentation of the application.
artisan command for creating views. You simply create a new file in the resources/views directory.The seeder is used to populate the database with test data.
Create a seeder:
php artisan make:seeder UsersTableSeederRun the seeder:
php artisan db:seedRun a specific seeder:
php artisan db:seed --class=UsersTableSeederLaravel uses different types of cache to improve performance.
Empty the application cache:
php artisan cache:clearEmpty the configuration cache:
php artisan config:clearClear the route cache:
php artisan route:clearGenerating a cache file for routes and improving performance
php artisan route:cache
Clearingthe cache for compiled views:
php artisan view:clear
php artisan tinkerLaunches Laravel's interactive console for testing code and interacting with your application.
php artisan storage:linkThis command creates a symbolic link named storage in your project's public directory.
Here is an example of a typical workflow using php artisan:
Create a new model with a migration and a controller:
php artisan make:model Product -mcrWrite the migration in database/migrations/YYYY_MM_DD_create_products_table.php and add the necessary fields.
Run the migration:
php artisan migrateCreate a new route in routes/web.php:
Route::resource('products', ProductController::class);Start the development server:
php artisan serveAccess the application via the browser and interact with the products via the routes generated automatically by the resource controller.
php artisan is a powerful and versatile tool that simplifies many common tasks in Laravel development. It allows you to manage the database, generate code, start a development server and much more, making the development of Laravel applications more efficient and organised.
Composer documentation: https: //laravel.com/docs/11.x/artisan
You now know how to :
php artisan list command to display all the commands available in Laravel.php artisan serve and even specify a different port.artisan commands.By following these steps, you'll become a true php artisan maestro, able to orchestrate the development of your Laravel applications with ease and efficiency 🎼👨💻.
Thank you for following us so far! If you have any questions or feedback on using these commands, don't hesitate to leave a comment below. Your experience enriches our community. See you soon for more exciting developments with Laravel! 😊🚀
Ask the LWS team and the community. Answers are published after moderation.