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

  • Handling API calls with createAsyncThunk.
  • Best practices for error handling and state transitions.
  • How configureStore works and why it's better than traditional Redux.
  • Adding middleware for additional functionality.

Dec 09, 2024
Read More
Tutorial
php

Debugging Common Middleware Issues in Laravel

Check if the middleware is assigned to the route or controller. Use route:list to verify:

   php artisan route:list

Nov 16, 2024
Read More
Tutorial
php

Laravel Best Practices for Sharing Data Between Views and Controllers

   <p>App Mode: {{ $globalConfig['app_mode'] }}</p>
   <p>Contact: {{ $globalConfig['support_email'] }}</p>

For frequently accessed but infrequently changing data, use caching.

Nov 16, 2024
Read More
Article

Google Chrome vs. Chromium: Understanding the Key Differences

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.

Key Takeaways:

Oct 24, 2024
Read More
Article
javascript

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

No preview available for this content.

Oct 24, 2024
Read More
Tutorial
bash

How to Grant MySQL Root Privileges for 127.0.0.1

Next, verify the new connection by attempting to log in using 127.0.0.1 as the host:

mysql -h 127.0.0.1 -u root -p

Oct 03, 2024
Read More
Tutorial
bash

How to Reset the MySQL Root Password Using DROP USER

   sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
   skip-grant-tables

Oct 03, 2024
Read More
Cheatsheet
json

JSON Operations in MySQL: Examples and Use Cases

You can update specific parts of a JSON document using the JSON_SET function.

UPDATE users
SET preferences = JSON_SET(preferences, '$.theme', 'light')
WHERE name = 'John Doe';

Aug 21, 2024
Read More
Tutorial

Getting Started with FFmpeg

ffmpeg -i input.mp4 -vf scale=1280:-1 output.mp4
  • -vf scale=1280:-1: The scale filter resizes the video. The width is set to 1280 pixels, and the height is automatically adjusted (-1 maintains the aspect ratio).

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

Snaps can accumulate multiple revisions, which can take up a lot of space. You can remove old, disabled revisions with the following script:

Create a script file:

Aug 17, 2024
Read More
Tutorial
javascript

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

Open the app.jsx file and set it up as follows:

   import React from 'react';
   import ReactDOM from 'react-dom/client';

   function App() {
       return (
           <div>
               <h1>Hello, React in Laravel with Vite!</h1>
           </div>
       );
   }

   const rootElement = document.getElementById('app');
   if (rootElement) {
       const root = ReactDOM.createRoot(rootElement);
       root.render(<App />);
   }

Aug 14, 2024
Read More
Code
bash

How to view free space on a Linux server

No preview available for this content.

Aug 11, 2024
Read More
Tutorial
bash

Finding the Top 10 Biggest Files on an Ubuntu Server

sudo find /path/to/directory -type f -exec du -h {} + | sort -rh | head -n 10
  • sudo: Runs the command with superuser privileges, which might be necessary for accessing certain files or directories.
  • find /path/to/directory -type f: Searches for files (-type f) in the specified directory and its subdirectories. Replace /path/to/directory with the target directory, or use / to search the entire file system.
  • -exec du -h {} +: Executes the du (disk usage) command for each file found, with -h providing human-readable sizes (e.g., MB, GB).
  • sort -rh: Sorts the files in reverse order by size, with the largest files listed first.
  • head -n 10: Displays the top 10 files from the sorted list.

Aug 11, 2024
Read More
Tutorial
sql

Optimizing SQL Queries: Indexing and Query Optimization Techniques

For a table employees:

CREATE INDEX idx_department
ON employees (department);

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

// Retrieve all data from the 'MyModel' table
$data = MyModel::all();

Jan 26, 2024
Read More
Code
bash

Create Resource Controller in Laravel

No preview available for this content.

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!