Laravel 5 HTTP/Requests - pass url parameter to the rules() method

后端 未结 2 1124
悲&欢浪女
悲&欢浪女 2021-01-25 20:04

I\'m trying to create a set of rules under the new \\HTTP\\Requests\\UpdateArticle class for the slug field, which needs to have unique fi

2条回答
  •  生来不讨喜
    2021-01-25 20:16

    You can retrieve route parameters by name with input():

    $id = Route::input('id');
    return [
        // ...
        'slug' => 'required|unique:articles,id,' . $id,
        // ...
    ];
    

    It's right there in the docs (scroll down to Accessing A Route Parameter Value)

提交回复
热议问题