小编Mar*_*ria的帖子

Laravel 5 中使用输入数组验证本地化?

对于可以添加和修改字段的动态表单:

通知

<input name="gallery[1][title]">
<input name="gallery[1][text]">
.
.
.
<input name="gallery[n][title]">
<input name="gallery[n][text]">
Run Code Online (Sandbox Code Playgroud)

在控制器中进行验证:

'gallery.*.file' => 'nullable|image',
'gallery.*.title' => 'nullable|string',
Run Code Online (Sandbox Code Playgroud)

在本地化文件中:

我永远不知道阵列中会有多少个。

'gallery.*.text' =>  'text of gallery 1',
'gallery.*.title' =>  'title of gallery 1',
Run Code Online (Sandbox Code Playgroud)

我该怎么写呢?

我想要这样的结果:

画廊名称 1

画廊名称 n

php localization laravel-5 laravel-validation laravel-localization

5
推荐指数
1
解决办法
1641
查看次数

在Laravel 5.5中验证之前更改$ request的值

我有一个表格route('users.create')

我将表单数据发送到该函数的contoller中:

public function store(UserRequest $request)
{

    return redirect(route('users.create'));
}
Run Code Online (Sandbox Code Playgroud)

为了验证,我在

App \ Http \ Requests \ Panel \ Users \ UserRequest;

class UserRequest extends FormRequest
{
    public function rules()
    {
        if($this->method() == 'POST') {
             return [
                 'first_name' => 'required|max:250',
Run Code Online (Sandbox Code Playgroud)

有用。

但是,如何first_name在验证之前(以及在保存到数据库之前)更改值?

(此外,如果验证失败,我想在 old('first_name')

更新资料

我尝试这样:

 public function rules()
    {
     $input = $this->all();


     $input['first_name'] = 'Mr '.$request->first_name;
     $this->replace($input);

     if($this->method() == 'POST') {
Run Code Online (Sandbox Code Playgroud)

它在之前有效,if($this->method() == 'POST') {但对验证或old()功能无效

laravel laravel-validation laravel-5.5

4
推荐指数
2
解决办法
4265
查看次数