mercredi 15 avril 2020

Laravel - Authorization In Controller

i try to give authorization just for the admin to do some job in my project .But it show me 403 (Forbidden)error Any help gyus?? this my AuthserviceProvider.php:

    $this->registerPolicies();
    Gate::define('Admin', function($user){
        return $user->role === 'admin';
                });

and this my taskController.php:

<?php

namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use App\Task;
use App\User;
use App\Projet;

use DB;
use phpDocumentor\Reflection\Types\Boolean;
use App\Notifications\NewTask;
class TaskController extends Controller
{
//
public function __construct()
{


}
public function store(Request $request){

  $this->authorize('Admin');
    $task = new Task();
    $task->projet_id=$request->key;
    $task->text = $request->text;
    $task->start_date = $request->start_date;
    $task->duration = $request->duration;
    $task->progress = $request->has("progress") ? $request->progress : 0;
    $task->parent = $request->parent;
    $task->sortorder = Task::max("sortorder") + 1;

    $task->save();

    return response()->json([
        "action"=> "inserted",
        "tid" => $task->id
    ]);
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire