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.
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:
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) { } }
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.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.