Controllers :-
===============
1. In laravel controller act as a directing traffic between Views and Models.
2. Controller is basically the central unit here we can write logic, call database
data,
call models , and also pass the view from the controller.
3. Create a controller :-
php artisan make:controller <controller_name>
php artisan make:controller HomeController
4. Controller name should be start with the capital letter.
5. Now Go to the app directory then http then controller.
6. We can create a function with the public private and protected access specifier,
by default this is
the public.
Example :- HomeController
--------------------------
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
//index function
public function index()
{
return "Home Controllers";
}
}
7. Now lets define a route for this controller,so go to the [Link] file and just
create the
route here.
Example :- [Link]
------------------
use App\Http\Controllers\HomeController;
Route::get('/home', [HomeController::class, 'index'])->name('[Link]');