DeveloperBreeze

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.

Continue Reading

Discover more amazing content handpicked just for you

Tutorial
javascript

Advanced State Management in React Using Redux Toolkit

Use these selectors in your component:

import React from 'react';
import { useSelector } from 'react-redux';
import { selectActiveUsers } from '../users/usersSlice';

const ActiveUsersList = () => {
  const activeUsers = useSelector(selectActiveUsers);

  return (
    <ul>
      {activeUsers.map((user) => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
};

export default ActiveUsersList;

Dec 09, 2024
Read More
Tutorial
php

Debugging Common Middleware Issues in Laravel

Ensure the middleware is registered in app/Http/Kernel.php under $middleware or $routeMiddleware:

   protected $routeMiddleware = [
       'auth' => \App\Http\Middleware\Authenticate::class,
       'verified' => \App\Http\Middleware\EnsureEmailIsVerified::class,
   ];

Nov 16, 2024
Read More
Tutorial
php

Laravel Best Practices for Sharing Data Between Views and Controllers

Open or create a service provider like AppServiceProvider:

   namespace App\Providers;

   use Illuminate\Support\ServiceProvider;
   use Illuminate\Support\Facades\View;

   class AppServiceProvider extends ServiceProvider
   {
       public function boot()
       {
           // Example global data
           $globalData = [
               'app_theme' => 'dark', // Current app theme
               'api_limit' => 100,    // API request limit
           ];

           // Share data with all views
           View::share('globalData', $globalData);
       }
   }

Nov 16, 2024
Read More
Article

Google Chrome vs. Chromium: Understanding the Key Differences

While Google Chrome and Chromium share a common codebase, they cater to different audiences through distinct features, branding, and functionalities. Google Chrome offers a polished, feature-rich browsing experience with seamless integration into Google's ecosystem, making it an excellent choice for users seeking convenience and robust support. On the other hand, Chromium provides a flexible, open-source platform that appeals to developers, privacy enthusiasts, and users who prefer greater control over their browsing environment.

Understanding these differences empowers users to select the browser that best aligns with their priorities—be it seamless updates and integrated services in Chrome or the customization and transparency offered by Chromium. Regardless of the choice, both browsers uphold high standards of performance and security, ensuring a reliable and efficient browsing experience.

Oct 24, 2024
Read More
Article
javascript

20 Useful Node.js tips to improve your Node.js development skills:

These Node.js tips will help you write more robust, secure, and efficient Node.js applications and improve your development workflow.

Oct 24, 2024
Read More
Tutorial
bash

How to Grant MySQL Root Privileges for 127.0.0.1

Once prompted, enter the MySQL root password.

By default, MySQL treats connections via localhost (Unix socket) and 127.0.0.1 (TCP/IP) differently. To resolve the issue, you need to grant privileges to root for connections via 127.0.0.1.

Oct 03, 2024
Read More
Tutorial
bash

How to Reset the MySQL Root Password Using DROP USER

This ensures that all changes you've made to users and permissions take effect immediately.

After resetting the password and recreating the root user, you need to revert the changes made to the MySQL configuration.

Oct 03, 2024
Read More
Cheatsheet
json

JSON Operations in MySQL: Examples and Use Cases

You can remove specific keys from a JSON object using the JSON_REMOVE function.

UPDATE users
SET preferences = JSON_REMOVE(preferences, '$.notifications.sms')
WHERE name = 'John Doe';

Aug 21, 2024
Read More
Tutorial

Getting Started with FFmpeg

ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt" output.mp4
  • -vf "subtitles=subtitles.srt": Adds the subtitles from the .srt file to the video.

Aug 21, 2024
Read More
Cheatsheet

Comprehensive React Libraries Cheatsheet

No preview available for this content.

Aug 21, 2024
Read More
Tutorial
bash

How to Free Up Disk Space on Ubuntu: A Comprehensive Guide to Clearing System Cache and Unnecessary Files

rm -rf ~/.cache/thumbnails/*

This command removes all thumbnails from the cache.

Aug 17, 2024
Read More
Tutorial
javascript

Integrating Vite with React in a Laravel Project: A Comprehensive Guide

Vite supports a wide range of plugins that can extend its functionality. For example, you can add TypeScript support or integrate with PWA (Progressive Web App) features:

   npm install @vitejs/plugin-vue @vitejs/plugin-pwa

Aug 14, 2024
Read More
Code
bash

How to view free space on a Linux server

  df -h /home
  • Inodes: To check free inodes instead of disk space, use the -i option:

Aug 11, 2024
Read More
Tutorial
bash

Finding the Top 10 Biggest Files on an Ubuntu Server

1.2G    /var/log/largefile.log
900M    /home/user/bigdata.dat
850M    /opt/application/hugefile.bin
...

If you're interested in both files and directories, you can use the du command:

Aug 11, 2024
Read More
Tutorial
sql

Optimizing SQL Queries: Indexing and Query Optimization Techniques

Ensure indexed columns are used:

SELECT e.name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.department_id;

Aug 03, 2024
Read More
Code
bash

Generate Model, Controller, and Middleware in Laravel

No preview available for this content.

Jan 26, 2024
Read More
Code
bash

Create Database Migration in Laravel

No preview available for this content.

Jan 26, 2024
Read More
Code
php

Retrieve All Data from Database Table in Laravel

No preview available for this content.

Jan 26, 2024
Read More
Code
bash

Create Resource Controller in Laravel

# Create a resource controller named 'MyResourceController'
php artisan make:controller MyResourceController --resource

Jan 26, 2024
Read More
Code
php

Querying Data from Database Table in Laravel

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!