How to manage Laravel with PHP Artisan and the Web Terminal?

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.

View the list of available commands

To see all the commands available in Laravel :

php artisan list

Common commands

Start the development server

To start the integrated development server :

php artisan serve

Starts 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=8080

Migration management

Migrations are used to manage the database structure.

  • Creating a new migration:

    php artisan make:migration create_users_table
    Creates a new migration file for the database.

    Run migrations:

    php artisan migrate

    Executes the database migrations and updates the database schema.

  • Undo the last migration:

    php artisan migrate:rollback

Managing templates

Templates are used to interact with the database tables.

  • Create a new model:

    php artisan make:model User
  • Create a model with a migration, a controller and a factory:

    php artisan make:model User -mcr

Managing controllers

Controllers manage the logic of the application.

  • Create a new controller:

    php artisan make:controller UserController
  • Create a resource controller:

    php artisan make:controller UserController --resource

Managing views

Views manage the presentation of the application.

  • Creating a new view (using Blade): Laravel does not have a dedicated artisan command for creating views. You simply create a new file in the resources/views directory.
Seeder management

The seeder is used to populate the database with test data.

  • Create a seeder:

    php artisan make:seeder UsersTableSeeder
  • Run the seeder:

    php artisan db:seed
  • Run a specific seeder:

    php artisan db:seed --class=UsersTableSeeder

Cleaning the cache

Laravel uses different types of cache to improve performance.

  • Empty the application cache:

    php artisan cache:clear
  • Empty the configuration cache:

    php artisan config:clear
  • Clear the route cache:

    php artisan route:clear
  • Generating a cache file for routes and improving performance

    php artisan route:cache

  • Clearingthe cache for compiled views:

    php artisan view:clear

Other commands

php artisan tinker

Launches Laravel's interactive console for testing code and interacting with your application.

php artisan storage:link

This command creates a symbolic link named storage in your project's public directory.

Complete example

Here is an example of a typical workflow using php artisan:

  1. Create a new model with a migration and a controller:

    php artisan make:model Product -mcr
  2. Write the migration in database/migrations/YYYY_MM_DD_create_products_table.php and add the necessary fields.

  3. Run the migration:

    php artisan migrate
  4. Create a new route in routes/web.php:

    Route::resource('products', ProductController::class);
  5. Start the development server:

    php artisan serve
  6. Access 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

Conclusion

You now know how to :

  • Use the php artisan list command to display all the commands available in Laravel.
  • Start the development server with php artisan serve and even specify a different port.
  • Manage your migrations, from creation to execution and cancellation using the various artisan commands.
  • Create and manipulate templates to interact with the database.
  • Setting up controllers to manage the logic of your application.
  • Create views using the Blade template system, even if this is done manually.
  • Use seeders to populate your database with test data.
  • Clean up the cache of different parts of the application to ensure that it works properly.

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! 😊🚀

Rate this article :

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

1mn reading

How do I connect to the Web Terminal with LWS Panel? (ssh web console)

4mn reading

How can I use GIT with the Web terminal on my LWS shared hosting?

2mn reading

How to change the PHP version of the LWS Panel Web Terminal

0mn reading

What can I do on my WordPress site using the Web Terminal?


Ask the LWS team and its community a question