How To Create Controller Using Laravel 8?

Dec 11, 2021 . Admin



Hello Dev,

This example is how to create controller using laravel 8?

Now let's see example of how to create controller example. We will check how to create controller. This is a short guide on create controller in laravel 8. Here you will learn how to create controller. Let's get started with how to create controller in laravel 8.

Here i will give you many example how to create controller using laravel 8.

Step 1 : Create Simple Controller

Let's create controller using laravel command. Laravel following command threw you can easily create controller.

php artisan make:controller DemoController


This controller you can see following directory or path.

app\Http\Controllers\DemoController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DemoController extends Controller
{
    //
}
Step 2 : Create Resource Controller

You can also create resource controller. Now we will see how to create resource controller using following command in laravel 8.

php artisan make:controller TestController --resource


This resource controller you can see following directory or path.

app\Http\Controllers\TestController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController 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