Laravel artisan cli useful commands


 artisan key:generate --ansi

 # Define a route
 Route::get('/', function(){
     return view('home');
 });

  # Clear cache
 php artisan cache:clear

  # Find route list
 php artisan route:list

  # Generate laravel error page templates
 https://laravel.com/docs/7.x/errors
 php artisan vendor:publish --tag=laravel-errors

  # Generate a model and a FlightFactory class…
 php artisan make:model Flight --factory
 php artisan make:model Flight -f

  # Generate a model and a FlightSeeder class…
 php artisan make:model Flight --seed
 php artisan make:model Flight -s

  # Generate a model and a FlightController class…
 php artisan make:model Flight --controller
 php artisan make:model Flight -c

  #  Generate a model and a migration, factory, seeder, and controller…
 php artisan make:model Flight -mfsc

  #  dump and die command - to print the results and exit
 dd($post);

  # find($id) takes an id and returns a single model.
  # If no matching model exist, it returns null.

  # findOrFail($id) takes an id and returns a single model. 
  # If no matching model exist, it throws an error1.

  # first() returns the first record found in the database. 
  # If no matching model exist, it returns null.

  # firstOrFail() returns the first record found in the database.
   # If no matching model exist, it throws an error1.
 
 # get() returns a collection of models matching the query.
 
 # pluck($column) returns a collection of just the values in the given column. 
 #  In previous versions of Laravel this method was called lists.

  # toArray() converts the model/collection into a simple PHP array.

   # create migration class
 php artisan migrate
 php artisan migrate:rollback
 php artisan migrate:fresh
 php artisan make:migration create_posts_table
 php artisan make:migration add_title_to_posts_table

  #  make:model
 php artisan help make:model

  # Tinker - cli to run php commands
 php artisan tinker

  #  install dependencies
 npm install

  #  compile sass files
 npm run dev
 npm run watch

  # compile files automatically as they are created
 npm run watch

  # dump all request details
 dump(request()->all());

  # Forms
 @csrf
 PUT PATCH DELETE
 @method('PUT');

  # install bootstrap
 composer require laravel/ui
 php artisan ui bootstrap
 php artisan ui bootstrap --auth
 npm install && npm run dev

  #  create users with faker in laravel 8
 User::factory()->make();
 User::factory()->create();


  # Enable website for maintenance mode
 php artisan down

  # Application is now in maintenance mode.
  # Bypass maintenance mode

 php artisan down --secret="###secret number"
 php artisan down --render="errors::503"
 php artisan down --redirect=/

  # disable maintenance mode
 php artisan up

Leave a Comment

Your email address will not be published. Required fields are marked *