0
    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 : []
Akash Kumar Verma
  • 3,185
  • 2
  • 16
  • 32

2 Answers2

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