Laravel 04
Laravel 04
=======================
1. Introduction to Laravel Controllers :-
------------------------------------------
1. MVC Architecture :-
--> User interacts with a view.
--> Views alerts controller of particular event.
--> Model alerts view that it has changed.
--> View grabs model data and updates itself.
2. Controllers :-
--> Controller acts as a directing traffic between views and Models.
--> It can group related request handling logic into a single class.
--> Controllers are defined in the "app/Http/Controllers" directory.
b. use :-
--> The 'use' is used ti import the class to the current file.
c. Command :-
php artisan make:controller <Controller_Name>
php artisan make:controller UserController
===================================================================================
===================
2. Routing Controllers in Laravel :-
------------------------------------
1. Routing Controllers :-
--> Routing controllers allow you to create controller classes
that have methods for handling requests.
Example :-
-----------
a. Controller :-
-----------------
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
b. Web.php :-
--------------
use App\Http\Controllers\UserController;
Route::get('/user',[UserController::class,'index']);
===================================================================================
===================
3. Resource Controllers in Laravel :-
-------------------------------------
1. A Resource Controller is used to create a controller that handles all
of your appliation's http requests.
Syntax :-
php artisan make:controller <Controller_Name> --resource
php artisan make:controller TestController --resource
Example :-
----------
a. Resource Controller:-
----------------------
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
}
}
b. Web.php :-
--------------
use App\Http\Controllers\TestController;
Route::resource('/test',TestController::class);
c. Assigning Route :-
---------------------
1. Actions Handled by Resource Controllers :-
----------------------------------------------
Verb URI Action
Route Name
GET /photos
index photos.index
GET /photos/create create
photos.create
POST /photos store
photos.store
GET /photos/{photo} show
photos.show
GET /photos/{photo}/edit edit
photos.edit
PUT/PATCH /photos/{photo} update
photos.update
DELETE /photos/{photo}
destroy photos.destroy