我使用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