Replies: 2 comments 4 replies
-
<?php
namespace App\Http\Controllers;
use App\Models\ClassSchool;
use App\Pipelines\FilterBySearch;
use Illuminate\Pipeline\Pipeline;
class ClassesController extends Controller
{
public function __construct(protected Pipeline $pipeline)
{
- $this->authorizeResource(ClassSchool::class);
+ $this->authorizeResource(ClassSchool::class, 'classes');
}
public function destroy(ClassSchool $classes)
{
$classes->delete();
return redirect()->back()->with('warning', __('classes.flash-warning'));
}
} Just a tip, in Laravel 10 you don't have to manually register policies. |
Beta Was this translation helpful? Give feedback.
3 replies
-
you were right, it was the name of the function parameters that were wrong and that prevented the model biding from working and therefore the policies afterwards |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
10.30.1
PHP Version
8.2
Database Driver & Version
Mysql 8.0
Description
Hi. I have a basic resource controller and I want to apply policy to it. $this->authorize() works perfectly, but there are too many methods to apply this to each one. So I found a method called authorizeResource(). But is doesn't work. It seems to me that it is my fault, but by the way I can't find a mistake..
this works well for my Exam model, but on my ClassSchool model, this is only work for non model required route, when a parameter is required, this make me à 403 everytime
Steps To Reproduce
ClassController :
ClassSchoolPolicy.php
route.:
AuthServiceProvider
Beta Was this translation helpful? Give feedback.
All reactions