Top Essential Laravel Commands for Developers

Top Essential Laravel Commands for Developers

Install Laravel

$ composer create-project laravel/laravel example-app 

  • This installs Laravel and creates a new project in the example-app directory.
  • Requires Composer to be installed.


Start laravel development server

$ php artisan serve

  • Starts a local development server at http://127.0.0.1:8000.
  • Useful for quick testing without setting up a full web server.

  • Create a migration

    Laravel migrations help manage database schema changes over time.

    $ php artisan make:migration migration-name


    Run Migrations

    $ php artisan migrate

    You can use this command to migrate and create tables in your database.


    Rollback Last Migration

    $ php artisan migrate:rollback

    Reverts the last batch of migrations

    Rollback a Specific Migration File:

    $ php artisan migrate:rollback --path=/database/migrations/2024_09_02_192702_create_size.php

    Rolls back only the specified migration file instead of all migrations.


    Reset Migrations

    $ php artisan migrate:reset

  • Rolls back all migrations (i.e., deletes all tables).
  • Unlike migrate:rollback, this does not just roll back the last batch but resets everything.

  • Create a Controller

    $ php artisan make:controller controllerName

  • Creates a new controller in app/Http/Controllers/.
  • Example: php artisan make:controller UserController creates UserController.php.

  • Database Seeding

    $ php artisan db:seed

  • Runs database seeders to populate tables with dummy data.
  • Seeder files are located in database/seeders/.

  • Link Storage to Public Folder

    $ php artisan storage:link

  • Creates a symbolic link from storage/app/public to public/storage.
  • Helps access files (e.g., images, uploads) stored in Laravel's storage system via the browser.
  • Comments