$basket_id = Cookie::get('basket_id');
$decrypted = Crypt::decryptString($basket_id);
private function getBasket() {
$basket_id = Cookie::get('basket_id');
$decrypted = Crypt::decryptString($basket_id);
if (!empty($basket_id)) {
try {
$this->basket = Basket::findOrFail($basket_id);
} catch (ModelNotFoundException $e) {
$this->basket = Basket::create();
}
} else {
$this->basket = Basket::create();
}
Cookie::queue('basket_id', $this->basket->id, 52560000);
}
Route::group([
'as' => 'basket.',
'prefix' => 'basket',
], function (){
Route::get('',[BasketController::class,'index'])->name('index');
Route::get('checkout',[BasketController::class,'checkout'])->name('checkout');
Route::post('add/{id}',[BasketController::class,'add'])->where('id','[0-9]+')->name('add');
Route::post('plus/{id}',[BasketController::class,'plus'])->where('id','[0-9]+')->name('plus');
Route::post('minus/{id}',[BasketController::class,'minus'])->where('id','[0-9]+')->name('minus');
Route::post('remove/{id}',[BasketController::class,'remove'])->where('id','[0-9]+')->name('remove');
Route::post('clear',[BasketController::class,'clear'])->name('clear');
});
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8"
},
public function handle($request, Closure $next)
{
dump('Encrypt!');
return parent::handle($request, $next);
}
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
use Closure;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
use Illuminate\Cookie\CookieValuePrefix;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class EncryptCookies extends Middleware
{
public function handle($request, Closure $next)
{
$response = parent::handle($request, $next);
dump('Encrypt!');
return $response;
}
}
\App\Http\Middleware\EncryptCookies::class
:protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\App\Http\Middleware\Your_Middleware_With_Cookies_Must_Be_Here_Or_Below::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\App\Http\Middleware\CheckAuth::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],