How to create Controller in Laravel using Artisan Command

How to create Controller in Laravel using Artisan Command

In this post we will give you information about How to create Controller in Laravel using Artisan Command. Hear we will give you detail about How to create Controller in Laravel using Artisan CommandAnd how to use it also give you demo for it if it is necessary.

In this article, i will show you how to create controller in laravel application. i will give you examples of create controller in laravel using cmd. we will use php artisan make controller command to create controller in laravel project.

You have to see this tutorial for creating controller in laravel using artisan command. you can easily create controller with windows cmd and terminal.

What is Controller in Laravel?

In Laravel Controller handle all request of routes files and write logic for Views and Models. Using Controller you can easily bind models and views logic on it.

You can easily create controller using laravel command.

Now we will see how to create controller on laravel. You can simply create controller by following command:

php artisan make:controller DemoController

Now you can see controller file on bellow path:

app/Http/Controllers/DemoController.php

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class DemoController extends Controller

{

}

You can easily connect route with controller as like bellow:

routes/web.php

Route::get('demo', 'DemoController@index');

app/Http/Controllers/DemoController.php

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class DemoController extends Controller

{

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

return view('demo');

}

}

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

php artisan make:controller ShowProfile --invokable

app/Http/Controllers/ShowProfile.php

Also see:How to Install Laravel in Ubuntu?

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class ShowProfile extends Controller

{

/**

* Handle the incoming request.

*

* @param IlluminateHttpRequest $request

* @return IlluminateHttpResponse

*/

public function __invoke(Request $request)

{

}

}

You can easily create resource controller. I already written tutorial on it. You can see that by clicking here: Resource Controller.

I hope it can help you…

Hope this code and post will helped you for implement How to create Controller in Laravel using Artisan Command. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

5  +  2  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US