add new rules for store and update package

This commit is contained in:
Moradi
2025-02-27 17:57:46 +03:30
parent 117a1cb160
commit 96de1c2fbe
2 changed files with 28 additions and 2 deletions
+23
View File
@@ -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");
}
}
}