DeveloperBreeze

Laravel Artisan Commands Cheatsheet

Introduction

Artisan is the command-line interface included with Laravel, providing numerous commands to assist in building applications. This cheatsheet covers essential commands for various tasks such as creating models, migrations, controllers, and more.


General Commands

  • List All Commands
  php artisan list
  • Display Help for a Command
  php artisan help [command]
  • Display the Current Laravel Version
  php artisan --version

Environment

  • Cache Configuration
  php artisan config:cache
  • Clear Configuration Cache
  php artisan config:clear
  • Cache Routes
  php artisan route:cache
  • Clear Route Cache
  php artisan route:clear
  • Cache Views
  php artisan view:cache
  • Clear View Cache
  php artisan view:clear
  • Clear All Caches
  php artisan cache:clear

Database

  • Run All Migrations
  php artisan migrate
  • Rollback the Last Migration Operation
  php artisan migrate:rollback
  • Reset All Migrations
  php artisan migrate:reset
  • Refresh All Migrations
  php artisan migrate:refresh
  • Fresh Migration (Rollback and Run All)
  php artisan migrate:fresh
  • Run Specific Seeders
  php artisan db:seed --class=SeederClassName
  • Create a New Migration
  php artisan make:migration create_table_name
  • Create a New Seeder
  php artisan make:seeder SeederName
  • Create a New Factory
  php artisan make:factory FactoryName

Models, Controllers, and More

  • Create a New Model
  php artisan make:model ModelName
  • Create a Model with Migration
  php artisan make:model ModelName -m
  • Create a New Controller
  php artisan make:controller ControllerName
  • Create a Resource Controller
  php artisan make:controller ControllerName --resource
  • Create a New Middleware
  php artisan make:middleware MiddlewareName
  • Create a New Event
  php artisan make:event EventName
  • Create a New Listener
  php artisan make:listener ListenerName
  • Create a New Job
  php artisan make:job JobName
  • Create a New Command
  php artisan make:command CommandName

Development

  • Serve the Application Locally
  php artisan serve
  • Generate Application Key
  php artisan key:generate
  • Run Tests
  php artisan test
  • Optimize the Framework for Better Performance
  php artisan optimize
  • Clear Compiled Classes and Services
  php artisan clear-compiled

Queue and Jobs

  • Start Processing Jobs on the Queue
  php artisan queue:work
  • Restart Queue Worker Daemon
  php artisan queue:restart
  • Flush Failed Queue Jobs
  php artisan queue:flush

Miscellaneous

  • Create a New Notification
  php artisan make:notification NotificationName
  • Create a New Mail Class
  php artisan make:mail MailClassName
  • Create a New Policy
  php artisan make:policy PolicyName
  • Create a New Rule
  php artisan make:rule RuleName

Conclusion

This cheatsheet provides a quick reference to the essential Laravel Artisan commands needed for day-to-day development tasks. For more detailed usage, refer to the Laravel documentation.

Related Posts

More content you might like

Tutorial
javascript

Advanced State Management in React Using Redux Toolkit

import { normalize, schema } from 'normalizr';

const userSchema = new schema.Entity('users');
const normalizedData = normalize(apiResponse, [userSchema]);
console.log(normalizedData);

Congratulations! You've built an advanced, scalable state management solution using Redux Toolkit. Key takeaways include:

Dec 09, 2024
Read More
Tutorial
php

Debugging Common Middleware Issues in Laravel

Use dependency injection for services your middleware requires:

   namespace App\Http\Middleware;

   use Closure;
   use App\Services\UserService;

   class CheckUserStatus
   {
       protected $userService;

       public function __construct(UserService $userService)
       {
           $this->userService = $userService;
       }

       public function handle($request, Closure $next)
       {
           if (!$this->userService->isActive($request->user())) {
               return redirect('inactive');
           }

           return $next($request);
       }
   }

Nov 16, 2024
Read More
Tutorial
php

Laravel Best Practices for Sharing Data Between Views and Controllers

   <ul>
       @foreach ($navigationMenu as $item)
           <li><a href="{{ $item['url'] }}">{{ $item['title'] }}</a></li>
       @endforeach
   </ul>
  • Use service providers for application-wide data.
  • Use middleware for context-sensitive or user-specific data.

Nov 16, 2024
Read More
Article

Google Chrome vs. Chromium: Understanding the Key Differences

In the vast landscape of web browsers, Google Chrome and Chromium stand out as two prominent options that share a common ancestry yet diverge in significant ways. While both browsers offer robust performance and a seamless browsing experience, understanding their distinctions can help users make informed choices based on their needs and preferences. This article delves into the main differences between Google Chrome and Chromium, exploring aspects such as development, branding, features, updates, privacy, and distribution channels.

Both Google Chrome and Chromium are web browsers developed by Google, but they cater to different user bases and purposes. Chromium serves as the open-source foundation upon which Chrome is built, incorporating additional proprietary features and branding elements that distinguish it from its open-source counterpart. Whether you're a developer, a privacy enthusiast, or a general user, understanding these differences can help you choose the browser that best aligns with your requirements.

Oct 24, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!