سلام . موقع استفاده مستقیم از دستورات authorize داخل متد مشکلی وجود نداره و برنامه به درستی اجرا میشه ولی موقع استفاده در construct این ابزار روی کل پروژه اجرا میشه و برنامه کلامتوقف میشه
سلام دوست عزیز
لطفا هر زمانی که به خطایی میخورید و قصد ایجاد تاپیک دارید هم متن خطا و هم کد خودتون رو قرار بدین تا در وقت خودتون و مجموعه صرفه جویی قابل توجهی کرده باشید.
محمد گازری۲۳ تیر ۱۴۰۱، ۰۴:۱۷
سلام مجدد.وقتی به این شکل استفاده میکنم مشکلی نیست
اینم کد داخل VideoPolicy که فقط قسمت update رو تکمیل کردم
namespaceApp\\Policies;
useApp\\Models\\User;
useApp\\Models\\Video;
useIlluminate\\Auth\\Access\\HandlesAuthorization;
useIlluminate\\Auth\\Access\\Response;
classVideoPolicy{
useHandlesAuthorization;
/**
* Determine whether the user can view any models.
*
* @param \\App\\Models\\User $user
* @return \\Illuminate\\Auth\\Access\\Response|bool
*/publicfunctionviewAny(User $user)
{
//
}
/**
* Determine whether the user can view the model.
*
* @param \\App\\Models\\User $user
* @param \\App\\Models\\Video $video
* @return \\Illuminate\\Auth\\Access\\Response|bool
*/publicfunctionview(User $user, Video $video)
{
//
}
/**
* Determine whether the user can create models.
*
* @param \\App\\Models\\User $user
* @return \\Illuminate\\Auth\\Access\\Response|bool
*/publicfunctioncreate(User $user)
{
//
}
/**
* Determine whether the user can update the model.
*
* @param \\App\\Models\\User $user
* @param \\App\\Models\\Video $video
* @return \\Illuminate\\Auth\\Access\\Response|bool
*/publicfunctionupdate(User $user, Video $video)
{
return$video->user_id == $user->id
? Response::allow()
: Response::deny(__('maseeges.You must be an administrator'));
}
/**
* Determine whether the user can delete the model.
*
* @param \\App\\Models\\User $user
* @param \\App\\Models\\Video $video
* @return \\Illuminate\\Auth\\Access\\Response|bool
*/publicfunctiondelete(User $user, Video $video)
{
//
}
/**
* Determine whether the user can restore the model.
*
* @param \\App\\Models\\User $user
* @param \\App\\Models\\Video $video
* @return \\Illuminate\\Auth\\Access\\Response|bool
*/publicfunctionrestore(User $user, Video $video)
{
//
}
/**
* Determine whether the user can permanently delete the model.
*
* @param \\App\\Models\\User $user
* @param \\App\\Models\\Video $video
* @return \\Illuminate\\Auth\\Access\\Response|bool
*/publicfunctionforceDelete(User $user, Video $video)
{
//
}
}
هادی امانی۲۳ تیر ۱۴۰۱، ۰۷:۰۶
چرا مجددا اومدید دسترسی رو توی متد update بررسی کردید؟
/**
* Determine whether the user can update the model.
*
* @param \\App\\Models\\User $user
* @param \\App\\Models\\Video $video
* @return \\Illuminate\\Auth\\Access\\Response|bool
*/
public function update(User $user, Video $video)
{
return $video->user_id == $user->id
? Response::allow()
: Response::deny(__('maseeges.You must be an administrator'));
}
محمد گازری۲۳ تیر ۱۴۰۱، ۰۷:۱۷
این روش دقیقا مثل خود فیلم بوده
هادی امانی۲۳ تیر ۱۴۰۱، ۰۷:۳۴
متن خطاتون رو قرار میدین
محمد گازری۲۳ تیر ۱۴۰۱، ۰۷:۴۴
خطا نمیده دسترسی کل برنامه رو با 403 میبنده
هادی امانی۲۳ تیر ۱۴۰۱، ۰۷:۴۸
خب الان policy اجرا شده
شرط هاتون رو بررسی کنید
محمد گازری۲۳ تیر ۱۴۰۱، ۱۰:۰۸
میدونم policy اجرا شده .
سوال من کلا اینه چرا بدون نوشتن هیچ فیلتری در VideoPolicy دسترسی به صفحه ایندکس هم قطع میشه وقتی از construct استفاده میکنم؟
هادی امانی۲۳ تیر ۱۴۰۱، ۱۴:۱۵
توی policy چک کنید false برگشت داده شده یا نه
محمد گازری۲۳ تیر ۱۴۰۱، ۱۴:۲۴
هادی امانی۲۳ تیر ۱۴۰۱، ۱۴:۲۵
کد استاد در پایین ویدیوهای بعدی پیوست شده
با کد خودتون مقایسه کنید اگر به نتیجه نرسیدید پروژتون رو روی گیتهاب پوش کنید لینکش رو قرار بدین