Laravelには2つのgetがある。
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.phpと
vendor/laravel/framework/src/Illuminate/Support/Collection.php
$p = Post::where('id', '<', 3)->get();
これはCollectionの配列になる idを取るにはpluck使うこと
$p = Post::where('id', '<', 3)->get(['id']);
これもCollectionの配列になる。
$q = collect(['id' => 1, 'name' => 'tom']);
$r = $q->get('id');
これはidを取得。1という数値になる。
配列の中身を取るのと変わらない。
つまりのところ、
Post::get(['id'])->get(0)->id
なんて書き方になるのだ。
そしてLaravelには2つのCollectionが存在する。
object(Illuminate\Support\Collection)と
object(Illuminate\Database\Eloquent\Collection)の2つ。
前者はcollect()で作ったCollection。
後者はelloquentのget()で取ったCollection。
前者は$collect['name']で取れるけど後者は$collect->nameになるので注意。
select tag_id from post_tag where post_id = 1;
PostTag::where('post_id', $data->id)->pluck('tag_id')->toArray();