public function plan($id){
$video = DB::select("SELECT * FROM `video` WHERE `video_episod` = ".$id." ");
dd($video);
return view('users.subplan', ['plan' => $plan]);
}
dd($video);
result : []
Asked
Active
Viewed 69 times
0

Akash Kumar Verma
- 3,185
- 2
- 16
- 32

ramani ajay
- 9
- 3
-
use this code: return view('users.subplan',['video'=>$video]); – Yasin Patel Feb 14 '20 at 05:29
-
[The docs aren't clear](https://laravel.com/docs/5.8/queries#selects)? – Don't Panic Feb 14 '20 at 11:03
2 Answers
1
If you expect multiple records in response then use get();
$videos = DB::table('video')->where('video_episod',$id)->get();
If you expect only one record in response then use first();
$video = DB::table('video')->where('video_episod',$id)->first();

Dilip Hirapara
- 14,810
- 3
- 27
- 49
-
are you sure that your `video_episod` field is matched with `$id`? can you `dd($id)` and check that id is in video_episod exist or not? – Dilip Hirapara Feb 14 '20 at 06:03
0
you can't do it like that. DB::select()
is for the column that you want to select. if you want a raw query to run in laravel you need to do it like this
public function plan($id){
$video = DB::raw("SELECT * FROM `video` WHERE `video_episod` = ".$id." ");
dd($video);
return view('users.subplan',['plan'=>$plan]);
}
dd($video);
or like this
public function plan($id){
$video = DB::select(DB::raw("SELECT * FROM `video` WHERE `video_episod` = ".$id." "));
dd($video);
return view('users.subplan',['plan'=>$plan]);
}
dd($video);
just try both of them. im not entirely sure.
hope it helps.

Jovs
- 852
- 7
- 23
-
-
I updated it to `video_episode` if its still not found data maybe you can check if your `$id` has a value. – Jovs Feb 14 '20 at 05:51
-
no...database name same "video_episod" Result: Collection {#326 ▼ #items: [] } – ramani ajay Feb 14 '20 at 05:59
-