Laravel5 表單驗證問題

來源:互聯網
上載者:User

為什麼設定了表單驗證的attributes仍然不顯示其設定的值?

:
設定了

$attributes = array(            "title" => '標題',            'content' => '本文'        );

提示仍然是title 不能小於10個字 而不是標題 不能小於10個字

有用過的大神知道是怎麼回事沒。

貌似圖片掛了,:http://7xjkan.com1.z0.glb.clouddn.com/QQ%E5%9B%BE%E7%89%8720151026170220.png

controller:

    public function update(Request $request,$id)    {        $rules = array(            'title' => 'required|max:255|min:10',            'content' => 'required|min:50|max:20000',        );        $message = array(            "title.required"=> ":attribute 不可為空",            "title.min"=> ":attribute 不能小於10個字",            "title.max"=> ":attribute 不能超過50個字",            "content.required"=>":attribute 不可為空",            "content.min"=>":attribute 不能小於50個字",            "content.max"=>":attribute 不能超過20000個字"        );        $attributes = array(            "title" => '標題',            'content' => '本文'        );        /*$this->validate($request, [            'title' => 'required|max:255|min:5',            'content' => 'required',        ]);*/        $this->validate($request,$rules,$message,$attributes);        $article = Article::find($id);        $article->title = \Input::get('title');        $article->content = \Input::get('content');        if ($article->save()) {            return \Redirect::to('article');        } else {            return \Redirect::back()->withInput()->withErrors('儲存失敗!');        }    }

視圖:

@extends('app')@section('content')

Article

@if (count($errors) > 0) Whoops! There were some problems with your input.

    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif @stop

回複內容:

為什麼設定了表單驗證的attributes仍然不顯示其設定的值?

:
設定了

$attributes = array(            "title" => '標題',            'content' => '本文'        );

提示仍然是title 不能小於10個字 而不是標題 不能小於10個字

有用過的大神知道是怎麼回事沒。

貌似圖片掛了,:http://7xjkan.com1.z0.glb.clouddn.com/QQ%E5%9B%BE%E7%89%8720151026170220.png

controller:

    public function update(Request $request,$id)    {        $rules = array(            'title' => 'required|max:255|min:10',            'content' => 'required|min:50|max:20000',        );        $message = array(            "title.required"=> ":attribute 不可為空",            "title.min"=> ":attribute 不能小於10個字",            "title.max"=> ":attribute 不能超過50個字",            "content.required"=>":attribute 不可為空",            "content.min"=>":attribute 不能小於50個字",            "content.max"=>":attribute 不能超過20000個字"        );        $attributes = array(            "title" => '標題',            'content' => '本文'        );        /*$this->validate($request, [            'title' => 'required|max:255|min:5',            'content' => 'required',        ]);*/        $this->validate($request,$rules,$message,$attributes);        $article = Article::find($id);        $article->title = \Input::get('title');        $article->content = \Input::get('content');        if ($article->save()) {            return \Redirect::to('article');        } else {            return \Redirect::back()->withInput()->withErrors('儲存失敗!');        }    }

視圖:

@extends('app')@section('content')

Article

@if (count($errors) > 0) Whoops! There were some problems with your input.

    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif @stop

'custom' => [        'title' => [            'required' => '標題不可為空',        ],    ],

找到resources/lang/en/validation.php中的custome,這個滿足你的要求不?更多的Laravel 5教程:

https://laravist.com/series/laravel-5-basic

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.