DEV Community

Arman Rahman
Arman Rahman

Posted on

Create Custom Artisan Command in Laravel

Sometimes we need to create custom commands to fast-forward our tasks. So here is the process to create your custom command for your Laravel project.

First Create a command class with this command -

php artisan make:command CustomCommand
Enter fullscreen mode Exit fullscreen mode

After that, it will create a file on this path -

app\Console\Commands\CustomCommand.php

Then Update your custom command like this -

protected $signature = 'make:files {name}';
Enter fullscreen mode Exit fullscreen mode

Add your command description and update your custom conditions on handle() method.

Here is added my conditions -

public function handle()
    {
        $name = $this->argument('name');

        $this->call('make:model', [
            'name' => $name,
            '-m' => true,
        ]);

        $this->call('make:controller', [
            'name' => "{$name}Controller",
        ]);

        $this->call('make:request', [
            'name' => "{$name}/{$name}StoreRequest",
        ]);

        $this->call('make:request', [
            'name' => "{$name}/{$name}UpdateRequest",
        ]);

        $this->info("Resource files for {$name} have been generated.");

        return Command::SUCCESS;
    }
Enter fullscreen mode Exit fullscreen mode

Done You have successfully created your command for your project.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs