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

后端 未结 2 1123
悲&欢浪女
悲&欢浪女 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)

    0 讨论(0)
  • 2021-01-25 20:24

    To get URL parameters from the URL:

    $this->route('id');
    

    A great discussion on this were also asked here.

    0 讨论(0)
提交回复
热议问题