To create a new controller in Laravel, you can follow these steps:
php artisan make:controller NewController
This will create a new controller file named NewController.php
in the app/Http/Controllers
directory.
index
to return a view:<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class NewController extends Controller
{
public function index()
{
return view('new.index');
}
}
Note: Make sure you define the proper namespace and extend the base Controller
class.
You can now use the newly created controller in your routes or other parts of your Laravel application.