Laravel 9 Controller Example Tutorial

May 10, 2022 . Admin

Hello Friends,

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

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

Create Simple Controller

You can easily create a controller using laravel 9 command. Now we will see how to create a controller on laravel 9. You can simply create a controller by following the 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 a resource controller using laravel 9 command. Now we will see how to create a resource controller on laravel 9. You can simply create a resource controller by following the command:

php artisan make:controller DemoController --resource

Now you can see the resource controller file on the below 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 9