LoginSignup
0
0

More than 1 year has passed since last update.

Laravel Tinkerの使い方

Last updated at Posted at 2021-10-31

はじめに

LaravelでクエリビルダやEloquentを用いて、実際にデータの取得ができるか確かめたい時に便利です。
コマンドにその処理を書く事で、実際にどういったデータが取得できるか確認できます。

目次

  1. tinkerを起動する
  2. 試したい処理を書く
  3. 上記の処理で取得したデータを表示
  4. tinkerを終了する

Tinkerを起動する

tinkerを使用するには下記コマンドを入力

$ php artisan tinker

試したい処理を書く

ユーザーidが1であるユーザーの情報が取得できるか確かめたい。

User::where('id', 1)->get();

上記の処理で取得したデータを表示

=> Illuminate\Database\Eloquent\Collection {#4753
     all: [
       App\Models\User {#4741
         id: 1,
         name: "山田 太郎",
         email: "test@exampe.co.jp",
         created_at: "2021-10-23 16:59:02",
         updated_at: "2021-10-23 16:59:02",
         deleted_at: null,
       },
     ],
   }

Tinkerを終了する

q を入力してEnterでTinkerを閉じる。

>>> q
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