mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 00:01:04 +03:30
add new rules for store and update package
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\Item;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class ValidateItemOwnership implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
$item = Item::find($value);
|
||||
if(!($item && $item->user_id === auth()->id())){
|
||||
$fail(":attribute have invalid ownership");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user