Help us understand the problem. What is going on with this article?

laravel4 validateのattributeの設定

More than 5 years have passed since last update.

エラーメッセージの:attributeに日本語を設定する

ex)http://stackoverflow.com/questions/17047116/laravel-validation-attributes-nice-names

カスタムvalidateの設定
http://qiita.com/MasatoYoshioka@github/items/64784c986e9e54b0d404

CustomValidator.php
    /* validate カスタムattributeの設定
    *
    */
    public function setAttributeNames(array $attributes)
    {
        $this->customAttributes = $attributes;
        return $this;
    }

Model.php
class Model extends Eloquent
{
    protected $table   = 'models';
    protected $guarded = array( 'id' );

    public static $validate_attributes = [
        'name' => '名前',
    ];

    public static function validateCreate( $input )
    {
        $rules = [
            'name' => 'required',
        ];
        $validator = Validator::make( $input, $rules );
        return $validator->setAttributeNames( self::$validate_attributes );
    }
}

Controller.php
    public function store()
    {
        try{
            $input     = Input::all();
            $validator = Model::validateCreate( $input );
            if( $validator->fails() ){
                return Redirect::back()
                        ->withErrors( $validator );
            }
       //ここに成功時の処理
        }catch( Exception $e ){
            return Redirect::back()
                    ->with( 'error_message', 'errorです' );
        }
    }
View.php
<div class="form-group">
    <label class="col-sm-3 control-label">名前</label>
    <div class="col-sm-9">
{{ Form::text( 'name' ,null, [ 'class' => 'form-control' ]) }}
{{ $errors->first( 'name') }}
    </div>
</div>
<p class="text-center"><button type="submit" class="btn btn-primary" rule="button">購入</button></p>

名前を未入力でエラーを出すと
「名前は必須です。」
と表示される。

OK

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away