laravel5でごく普通にDBからデータを取ってこようとしたときに起きるのですが、
データベース(test) id name num ------------ 1 test1 10 2 test2 20
Servace ※フォルダはリポジトリパターンを意識したものになってます。 $idの中身は仮に2とする <?php namespace App\Services; use App\Repositories\TestRepository; class TestService { protected $TestRepository; public function __construct(TestRepository $TestRepository) { $this->TestRepository = $TestRepository; } public function test($id) { $data = $this->TestRepository->find_test($id); } }
Repositories <?php namespace App\Repositories; use App\Repositories\Eloquent\Test; class TestRepository { protected $model; public function __construct(Test $Test) { $this->model = $Test; } public function find_test($id) { $data = $this->model->where('id',$id)->first(); return $data; } }
Servaceの返り値 $data = 'id'=>2, 'name'=>'test2', 'num'=>0 //ここだけ何故か0
このように一部だけ中身が空か0で返ってきてしまいます。どうしてこうなるのか見当がつかないのですが、どの辺を疑ったほうがよいのでしょうか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/11/21 01:27