samedi 10 septembre 2022

Undefined variable: sub inside the foreach loop in laravel

Controller:

public function dashboard()
{
    $course = Course::all();
    return view('content.dashboard',compact('course'));
}

View:

@foreach($course as $year)

    $sub = \App\Models\SubCourse::where('course_id',$year->id)->first();
    @dd($sub->id);

@endforeach

In the above code I am trying to get value of SubCourse but it throw an error i.e. Undefined variable: sub (View: C:\xampp\htdocs\example\resources\views\content\dashboard.blade.php). I don't know why? Please help me.

Thank you



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/9L0Eptg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire