我使用Laravel 5.3,我想提出的請求文件的查詢,我提出來有一個表單,用戶可以編輯一些驗證規則,他的渠道。在該文件中,我想作一個查詢這將是這個樣子:Laravel - 如何獲取對象的參數的請求文件
$channelId = Auth::user()->channels()->where('id', $this->id)->get();
所以,我可以得到頻道ID和從規則陣列排除,這是文件的樣子:
public function rules()
{
$channelId = Auth::user()->channels()->where('id', $this->id)->get();
return [
'name' => 'required|max:255|unique:channels,name,' . $channelId,
'slug' => 'required|max:255|alpha_num|unique:channels,slug,' . $channelId,
'description' => 'max:1000',
];
}
我不確定如何獲取該請求文件中正在更新的對象的channel id
?
你的意思是說,你不知道如何獲得你使用表單發送的id(你使用的例子中是$ this-> id)? – Silwerclaw
是的,這是正確的 – Marco
你在裏面Request對象,這意味着你可以使用它的內置功能,用於檢索輸入函數:$ this->輸入(),$這個 - >輸入(「ID」)。閱讀更多在https://laravel.com/docs/5.3/requests#retrieving-input – Silwerclaw