我想在laravel form請求授權裏面訪問路由請求參數。我無法找到一個描述這一點的例子。如何在表單請求中訪問請求的非id屬性?
// Works fine when you want id
dd($this->route('myResourceName'));
// How to do when I want something else???
dd($this->route('anotherAttribute'));
// Above give null probably because it is a resourceful controller
在一個側面說明,我不明白這個設計,有什麼意義? $ this-> route('anyAttribute')會是最簡單的,對吧?
編輯:更廣泛的例子
class UpdateSlotAPIRequest extends APIRequest
{
public function __construct(){
parent::__construct();
$this->slot = Slot::find($this->route('slot'));
$this->access_token = $this->route('access_token'); // this is not working!
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
// If administrator is logged in all is good.
// If slot is free its ok.
// If its not free but you provide good access_token its also fine.
return Auth::check() || $this->slot->isAvailable() || $this->slot->isValidAccessToken($this->access_token);
}
...
```
發現它是什麼'任意請求parameters'是什麼意思?你的意思是路由參數? –
只更正路線參數! – Anders
你可以添加你如何使用它的例子。你是從控制器還是中間件調用它? –