経緯
Eloquentの戻り値をセッションにそのまま代入したらセッションが複雑になってしまった。
やりたいこと。
- Eloquentを使って欲しい情報だけを取得したい。
- 1の取得はなるべくLaravelの機能だけを使って簡単に実現させる。(自分でforeash文を使って処理を作るのは手間なので)
PHP
1// PossibleDateはモデル 2$var = PossibleDate::select('possible_dates')->where('event_id', '5')->get();
PossibleDateというテーブルにevent_id=5
である複数行のpossible_dates
だけを取得するようにしたいのですが、
var_dump($var)
した結果がこちら
PHP
1object(Illuminate\Database\Eloquent\Collection)[266] 2 protected 'items' => 3 array (size=2) 4 0 => 5 object(App\PossibleDate)[284] 6 protected 'connection' => string 'mysql' (length=5) 7 protected 'table' => string 'possible_dates' (length=14) 8 protected 'primaryKey' => string 'id' (length=2) 9 protected 'keyType' => string 'int' (length=3) 10 public 'incrementing' => boolean true 11 protected 'with' => 12 array (size=0) 13 empty 14 protected 'withCount' => 15 array (size=0) 16 empty 17 protected 'perPage' => int 15 18 public 'exists' => boolean true 19 public 'wasRecentlyCreated' => boolean false 20 protected 'attributes' => 21 array (size=1) 22 'possible_dates' => string '2022-06-17 00:00:00' (length=19) 23 protected 'original' => 24 array (size=1) 25 'possible_dates' => string '2022-06-17 00:00:00' (length=19) 26 protected 'changes' => 27 array (size=0) 28 empty 29 protected 'casts' => 30 array (size=0) 31 empty 32 protected 'dates' => 33 array (size=0) 34 empty 35 protected 'dateFormat' => null 36 protected 'appends' => 37 array (size=0) 38 empty 39 protected 'dispatchesEvents' => 40 array (size=0) 41 empty 42 protected 'observables' => 43 array (size=0) 44 empty 45 protected 'relations' => 46 array (size=0) 47 empty 48 protected 'touches' => 49 array (size=0) 50 empty 51 public 'timestamps' => boolean true 52 protected 'hidden' => 53 array (size=0) 54 empty 55 protected 'visible' => 56 array (size=0) 57 empty 58 protected 'fillable' => 59 array (size=0) 60 empty 61 protected 'guarded' => 62 array (size=1) 63 0 => string '*' (length=1) 64 1 => 65 object(App\PossibleDate)[285] 66 protected 'connection' => string 'mysql' (length=5) 67 protected 'table' => string 'possible_dates' (length=14) 68 protected 'primaryKey' => string 'id' (length=2) 69 protected 'keyType' => string 'int' (length=3) 70 public 'incrementing' => boolean true 71 protected 'with' => 72 array (size=0) 73 empty 74 protected 'withCount' => 75 array (size=0) 76 empty 77 protected 'perPage' => int 15 78 public 'exists' => boolean true 79 public 'wasRecentlyCreated' => boolean false 80 protected 'attributes' => 81 array (size=1) 82 'possible_dates' => string '2022-06-17 00:00:00' (length=19) 83 protected 'original' => 84 array (size=1) 85 'possible_dates' => string '2022-06-17 00:00:00' (length=19) 86 protected 'changes' => 87 array (size=0) 88 empty 89 protected 'casts' => 90 array (size=0) 91 empty 92 protected 'dates' => 93 array (size=0) 94 empty 95 protected 'dateFormat' => null 96 protected 'appends' => 97 array (size=0) 98 empty 99 protected 'dispatchesEvents' => 100 array (size=0) 101 empty 102 protected 'observables' => 103 array (size=0) 104 empty 105 protected 'relations' => 106 array (size=0) 107 empty 108 protected 'touches' => 109 array (size=0) 110 empty 111 public 'timestamps' => boolean true 112 protected 'hidden' => 113 array (size=0) 114 empty 115 protected 'visible' => 116 array (size=0) 117 empty 118 protected 'fillable' => 119 array (size=0) 120 empty 121 protected 'guarded' => 122 array (size=1) 123 0 => string '*' (length=1)
期待してたもの
PHP
1array (size=3) 2 0 => string '2022-06-17 00:00:00' 3 1 => string '2022-06-17 00:00:00'
もしEloquentを使わない方法でしかきれいに値を出力できないのでしたらそちらの方法で教えてください。
よろしくお願い致します。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/05 04:29 編集