I have some models inside folder also i created policy incide same named folder so that my folder structure looks good but policy isn't working example
example models App\Models\Shop\Example.php Policies App\Policies\Shop\ExamplePolicy.php
if i create policy like this policy didn't work in resource
but it works in App\Models\Shop\Example.php Policies App\Policies\ExamplePolicy.php
also works in this App\Models\Example.php Policies App\Policies\ExamplePolicy.php
btw my resource also in filament/resources/shop/
In general if i put my policy in folder it didn't work yes i check namespace and other thing it is correct
so how can i connect resource with policy in this situation
Gate::guessPolicyNamesUsing(function (string $modelClass){ // follow the same namespace as the model $targetPolicy = str_replace('Models', 'Policies', $modelClass) . 'Policy'; return class_exists($targetPolicy) ? $targetPolicy : null; });
Gate::guessPolicyNamesUsing(function (string $modelClass){ // follow the same namespace as the model $targetPolicy = str_replace('Models', 'Policies', $modelClass) . 'Policy'; return class_exists($targetPolicy) ? $targetPolicy : null; });
This will follow same policy structure same as in model.
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.