Laravel 8 Controller Example Tutorial

10-Apr-2023

.

Admin

Hello Friends,

Now let's see we will create simple controller and resource controller using artisan command in laravel 8. This tutorial will give how to create controller in laravel 8. In this post i am going to show you how to create simple controller and resource controller in laravel 8.

In this tutorial, I will give simple and easy way to create controller in laravel 8 application So let's see the bellow example:

Create Simple Controller


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 TestController

Now you can see controller file on bellow path:

app\Http\Controllers\TestController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller

{

//

}

Create Resource Controller

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

php artisan make:controller DemoController --resource

Now you can see resource controller file on bellow path:

app\Http\Controllers\DemoController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DemoController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

//

}

/**

* Show the form for creating a new resource.

*

* @return \Illuminate\Http\Response

*/

public function create()

{

//

}

/**

* Store a newly created resource in storage.

*

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

*/

public function store(Request $request)

{

//

}

/**

* Display the specified resource.

*

* @param int $id

* @return \Illuminate\Http\Response

*/

public function show($id)

{

//

}

/**

* Show the form for editing the specified resource.

*

* @param int $id

* @return \Illuminate\Http\Response

*/

public function edit($id)

{

//

}

/**

* Update the specified resource in storage.

*

* @param \Illuminate\Http\Request $request

* @param int $id

* @return \Illuminate\Http\Response

*/

public function update(Request $request, $id)

{

//

}

/**

* Remove the specified resource from storage.

*

* @param int $id

* @return \Illuminate\Http\Response

*/

public function destroy($id)

{

//

}

}

It will help you...

#Laravel 8

#Laravel