Example 9-21. The authorization-to-method mappings of authorizeResource()
class ContactsController extends Controller
{
public function __construct()
{
// This call does everything you see in the methods below.
// If you put this here, you can remove all authorize()
// calls in the individual resource methods here.
$this->authorizeResource(Contact::class);
}
public function index()
{
$this->authorize('view', Contact::class);
}
public function create()
{
$this->authorize('create', Contact::class);
}
public function store(Request $request)
{
$this->authorize('create', Contact::class);
}
public function show(Contact $contact)
{
$this->authorize('view', $contact);
}
public function edit(Contact $contact)
{
$this->authorize('update', $contact);
}
public function update(Request $request, Contact $contact)
{
$this->authorize('update', $contact);
}
public function destroy(Contact $contact)
{
$this->authorize('delete', $contact);
}
}