how to create controller in laravel through cmd?

Today, We want to share with you how to create controller in laravel.In this post we will show you laravel resource controller example, hear for how to creates controller in laravel through cmd we will give you demo and example for implement.In this post, we will learn about How to creates Controller in Laravel? with an example.

Free Live Chat for Any Issue

How to creates Controller in Laravel using Artisan Command?

php artisan make:controller DemoController

app/Http/Controllers/DemoController.php

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
  
class DemoController extends Controller
{
       
}

You can easily connect route with controller as like bellow:

Read Also:  PHP Connection Mysql Database Steps

routes/web.php

Route::get('demo', '[email protected]');

app/Http/Controllers/DemoController.php

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
  
class DemoController extends Controller
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    public function index()
    {
        return view('demo');
    }
}

You can also creates controller with invokable controller using bellow command:

php artisan make:controller ShowProfile --invokable

app/Http/Controllers/ShowProfile.php

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
  
class ShowProfile extends Controller
{
    /**
     * Handle the incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function __invoke(Request $request)
    {
          
    }
}

Download

I hope you get an idea about laravel register controller.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.