Hi,
I'm using Laravel ^6.2 and the latest version of this package.
I put a folder for Policies into Entities of a module.
I pust this method into PostController, same as Laravel doc.
public function __construct()
{
$this->authorizeResource(Post::class, 'post');
}
But unfortunately I get an error:
authorizeresource does not exist
Please could you set us an example for this. Thanks.
The generated controller extends the default Illuminate\Routing\Controller not the usual App\Http\Controllers\Controller as in a fresh Laravel installation.
To be able to use authorization related methods you have to use the Illuminate\Foundation\Auth\Access\AuthorizesRequests trait in your class:
<?php
namespace Module\Posts\Http\Controllers;
// Add this use statement
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
class PostController extends Controller
{
use AuthorizesRequests;
public function __construct()
{
$this->authorizeResource(Post::class, 'post');
}
// ...
}
Thank you so much
Most helpful comment
The generated controller extends the default
Illuminate\Routing\Controllernot the usualApp\Http\Controllers\Controlleras in a fresh Laravel installation.To be able to use authorization related methods you have to use the
Illuminate\Foundation\Auth\Access\AuthorizesRequeststrait in your class: