0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Migrationでテーブルを作成する

Last updated at Posted at 2021-02-12

メモです。参考にしないでくださいね。:point_up:

Migrationファイルのひな形を作る
(今回はnewsテーブルを作る)

$ php artisan make:migration create_news_table

データの保存
Modelのひな形を生成
(今回はnewsモデルを作る)
(Model名は単数系)

$ php artisan make:model News

##Validationを定義
(Model内に定義します)


namespace App;

use Illuminate\Database\Eloquent\Model;

class News extends Model
{
    protected $guarded = array('id');

    // 以下を追記
    public static $rules = array(
        'title' => 'required',
        'body' => 'required',
    );
}

##エラーメッセージを日本語化
config/app.php で local を指定している箇所を編集し、en から ja に変更

'locale' => 'ja',

resources/lang/en を右クリックコピー
resources/lang の下にペースト、ファイル名を ja に変更

$ cp -rp resources/lang/en/* resources/lang/ja

resources/lang/ja ディレクトリにある validation.phpの
‘required’ の部分を下記のように書き換える

'required'             => ':attribute に入力が必要です。',
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?