57
53

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 5 years have passed since last update.

LaravelのSeeder単体で実行。

Last updated at Posted at 2015-05-27

Laravelの開発環境でusersテーブルにあるユーザーを削除してから作業したかったのでSeederを作ったメモ。
ユーザーを開発用の自分だけにする。

database/seeds/UserTableSeeder
<?php
use Illuminate\Database\Seeder;
use App\Models\User;

class UserTableSeeder extends Seeder {

    public function run()
    {
        // DatabaseSeeder.phpを使用せず単体で実行する場合必要
        Eloquent::unguard();
        // 全部消す  
        DB::table('users')->delete();
        // 開発用のユーザー追加
        User::create([  'id'         => 1,
                        'username'   => '佐藤',
                        'email_flag' => '',
                        'email'      => 'kick@punch.org',
                        'password'   => Hash::make('pass')
                    ]);
    }

}

usersテーブルのみデータ更新。

% php artisan db:seed --class=UserTableSeeder
57
53
2

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
57
53

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?