1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-02-24 03:03:55 +01:00
LinkAce/app/Http/Requests/NoteDeleteRequest.php

46 lines
926 B
PHP

<?php
namespace App\Http\Requests;
use App\Models\Note;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
class NoteDeleteRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @param Request $request
* @return bool
*/
public function authorize(Request $request)
{
// Check if the note ID was provided
if (!$request->get('note_id')) {
return false;
}
$note = Note::find($request->get('note_id'));
// Check if the note belongs to the user
if ($note->user_id !== auth()->user()->id) {
return false;
}
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'note_id' => 'required',
];
}
}