0
only()
およびexcept
メソッドを使用する場合、laravelに問題があります。laravel 5メソッドのみ()またはexcept()の問題
公式ドキュメント:
- https://laravel.com/docs/5.4/collections#method-only
- https://laravel.com/docs/5.4/collections#method-except
使用:
$data = Model::whereId($id)->first();
または$data = Model::whereId($id)->get()->except('updated_at', 'deleted_at');
私が取得:
{"id":21,"name":"new one","description":"desc","deleted_at":null,"created_at":"2017-03-08 16:23:01","updated_at":"2017-03-08 16:23:01"}
で:
$data = Model::whereId($id)->get()->only('id', 'name', 'description', 'created_at');
私は空の結果を取得します。
私は正しい方法でメソッドを呼び出すわけではないと確信しています。 $data->only('...')
や$data->except('...')
のようにDBから結果を取得した後に呼び出すことも試みました。
助けていただけたら幸いです!ありがとう!十分