LinkStack/app/Http/Middleware/LinkId.php

30 lines
502 B
PHP
Raw Normal View History

2023-11-02 22:02:20 +01:00
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
use App\Models\Link;
use Illuminate\Http\Request;
class LinkId
{
public function handle($request, Closure $next)
{
$linkId = $request->route('id');
$user = Auth::user();
$link = Link::find($linkId);
if (!$link) {
return abort(404);
}
if ($user->id !== $link->user_id) {
return abort(403);
}
return $next($request);
}
}