2017-09-12 72 views
0

我想將動態值傳遞給大門以防止刀片中的塊,例如。如果我想通過刀片頁面打印偶數。我可以通過@can將動態值傳遞給門嗎?

@for($i=0;$i<=10;$i++) 
@can('print-even',$i) // i know its not possible i want to is there any other way 
    <div > div to display </div> 
@endcan 
@endfor 
在AuthSerivceProvider.php

public function boot(GateContract $gate) 
{ 
    $this->registerPolicies($gate); 


    $gate->define('print-even', function($number){ 
     return $number % 2 == 0; 
    }); 


} 

像明智

,我想知道有沒有辦法做到傳遞動態值門?

回答

0

可以傳遞附加的簡單地增加柵極這樣

$gate->define('print-even', function($user,$number){ 
    return $number % 2 == 0; 
}); 

默認的第一個參數是當前驗證::用戶()。

+0

非常感謝你花花公子@Hectorda –

相關問題