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

import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';

// Async action for fetching users
export const fetchUsers = createAsyncThunk(
  'users/fetchUsers',
  async (_, thunkAPI) => {
    try {
      const response = await axios.get('https://jsonplaceholder.typicode.com/users');
      return response.data;
    } catch (error) {
      return thunkAPI.rejectWithValue(error.message);
    }
  }
);

const usersSlice = createSlice({
  name: 'users',
  initialState: {
    entities: [],
    status: 'idle',
    error: null,
  },
  reducers: {
    addUser: (state, action) => {
      state.entities.push(action.payload);
    },
    updateUser: (state, action) => {
      const { id, changes } = action.payload;
      const existingUser = state.entities.find((user) => user.id === id);
      if (existingUser) {
        Object.assign(existingUser, changes);
      }
    },
    deleteUser: (state, action) => {
      state.entities = state.entities.filter((user) => user.id !== action.payload);
    },
  },
  extraReducers: (builder) => {
    builder
      .addCase(fetchUsers.pending, (state) => {
        state.status = 'loading';
      })
      .addCase(fetchUsers.fulfilled, (state, action) => {
        state.status = 'succeeded';
        state.entities = action.payload;
      })
      .addCase(fetchUsers.rejected, (state, action) => {
        state.status = 'failed';
        state.error = action.payload;
      });
  },
});

export const { addUser, updateUser, deleteUser } = usersSlice.actions;
export default usersSlice.reducer;
  • Reducers: Define actions to manipulate the state (addUser, updateUser, deleteUser).
  • Async Actions: Handle API calls with createAsyncThunk.
  • Extra Reducers: Manage different states (loading, succeeded, failed) based on async actions.

Dec 09, 2024
Read More
Tutorial
php

Debugging Common Middleware Issues in Laravel

   Route::get('/dashboard', [DashboardController::class, 'index'])->middleware(['auth', 'verified']);

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

Nov 16, 2024
Read More
Tutorial
php

Laravel Best Practices for Sharing Data Between Views and Controllers

Consider an application where you need to:

  • Share app-wide settings (e.g., theme or API limits) with all views.
  • Make user-specific preferences (e.g., notification settings) accessible to controllers and views.
  • Dynamically load data blocks like navigation menus or notifications.

Nov 16, 2024
Read More
Article

Google Chrome vs. Chromium: Understanding the Key Differences

Additionally, Chromium serves as the foundation for several other browsers. Browsers like Opera, Microsoft Edge, and Brave build upon Chromium's codebase, adding their own unique features and branding. This modular approach allows these browsers to leverage Chromium's robust performance and security while differentiating themselves through additional functionalities and design choices.

For users interested in alternative Chromium-based browsers, the availability and distribution channels may vary, offering a range of options tailored to different preferences and needs.

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

To ensure all changes take effect, flush the privileges:

FLUSH PRIVILEGES;

Oct 03, 2024
Read More
Tutorial
bash

How to Reset the MySQL Root Password Using DROP USER

  sudo systemctl status mysql

This tutorial provided a step-by-step guide on resetting your MySQL root password using the DROP USER method. By dropping the existing root user and creating a new one with full privileges, you can resolve common issues related to root access and password management. Remember to always remove the skip-grant-tables option after completing the password reset to keep your MySQL server secure.

Oct 03, 2024
Read More
Cheatsheet
json

JSON Operations in MySQL: Examples and Use Cases

SELECT preferences->>'$.languages[1]' AS second_language
FROM users
WHERE name = 'Jane Smith';

To check if a value exists within a JSON array, use the JSON_CONTAINS function.

Aug 21, 2024
Read More
Tutorial

Getting Started with FFmpeg

  • To slow down the video (e.g., 2x slower):
  ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" output.mp4

Aug 21, 2024
Read More
Cheatsheet

Comprehensive React Libraries Cheatsheet

Introduction

React's ecosystem is vast, with a multitude of libraries that enhance its functionality and simplify development tasks. This cheatsheet covers a wide array of React libraries, organized by category, with brief descriptions of each. These libraries can help you build robust, maintainable, and efficient React applications.

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

This command removes all thumbnails from the cache.

Systemd keeps logs of system messages, and over time these can accumulate. You can clear old logs while keeping recent ones:

Aug 17, 2024
Read More
Tutorial
javascript

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

If you don’t already have a Laravel project, create one using Composer:

   composer create-project laravel/laravel my-react-laravel-app

Aug 14, 2024
Read More
Code
bash

How to view free space on a Linux server

When you run the df -h command, you might see output similar to the following:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        40G   25G   15G  63% /
udev            1.9G     0  1.9G   0% /dev
tmpfs           384M  1.2M  383M   1% /run
/dev/sda2       100G   50G   50G  50% /home

Aug 11, 2024
Read More
Tutorial
bash

Finding the Top 10 Biggest Files on an Ubuntu Server

This command lists the largest files and directories in the specified path.

By following this tutorial, you should be able to efficiently identify the largest files on your Ubuntu server. This information can help you manage disk space and make informed decisions about file storage and deletion.

Aug 11, 2024
Read More
Tutorial
sql

Optimizing SQL Queries: Indexing and Query Optimization Techniques

Use tools like EXPLAIN to understand query execution and identify bottlenecks.

EXPLAIN SELECT * FROM employees;

Aug 03, 2024
Read More
Code
bash

Generate Model, Controller, and Middleware in Laravel

# Generate a model named 'MyModel'
php artisan make:model MyModel

# Generate a controller named 'MyController'
php artisan make:controller MyController

# Generate a middleware named 'MyMiddleware'
php artisan make:middleware MyMiddleware

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

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!