mercredi 8 juin 2016

@can statement does not use multiple time into laravel 5.2?

I want to use multiple times @can statement in blade template. but here's problem that Nothing get output without last condition of @can statement:

//check user can create max slides as per plan
$gate->define('user_can_create_slide',function($user){
    if($user->type == "Super Admin"){
        return true;
    }
    //retrieve user purchased plan
    $getUserPlan = UserPlan::where('userid',$user->id)->with(['plan'])->first();

    //retrieve user created slides
    $userProjectSlide = User::where('id',$user->id)->with('projectslides')->first();

    //check project slides exists
    if(!empty($userProjectSlide)){
        //check user has purchase plan
        if(empty($getUserPlan)){
            return false;
        }
        $countMaxProjects = $getUserPlan->plan->maxslides;
        $maxProjects = $userProjectSlide->projectslides->count();
        if($maxProjects > $countMaxProjects){
            return false;
        }
    }
    return true;
});

in front.blade.php

@can('user_can_create_slide')
   {!! "Can We start program now?" !!}
@endcan
<div class="col-md-6 text-right">
@can('user_can_create_slide')
    <button type="button" class="btn btn-success btn-md" data-toggle="modal"
        data-target="#modal-screen-create">
        <i class="fa fa-plus-circle"></i> Create
    </button>
@endcan



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire