Home > Net >  Getting Undefined property: projekti when trying to print field fetched from databse
Getting Undefined property: projekti when trying to print field fetched from databse

Time:03-20

i get this error Undefined property: projekti when trying to print a field fetched from database this is the code that causes the error

   @foreach($dataOfProjects as $dp)
 
        <div >
            <h1  >{{$dp->projekti}}</h1>
        </div>    
    @endforeach

specifically the `{{$dp->projekti}}

this is the controller that is returning the dataOfProjects variable

public function specificClub(Request $request,$id){
    $data = Clubs::find($id);
    $dataOfProjects = DB::table('projektet') -> where('klubi', '=',$id);

    $teachers =  DB::table('mesuesit')->join('klubet','klubet.id','=','mesuesit.klubi_ne_kujdesari')->select('mesuesit.emri')->where('klubet.emri','=','rrobotike')->get();//Per te mare emrin e mesuesve te ketij klubi
    return view('specificClub',  compact('data','dataOfProjects','teachers'));
}

This is the table klubet enter image description here

and this is the table projektet enter image description here

CodePudding user response:

Add ->get() for multiple results or ->first() for one result to this line:

$dataOfProjects = DB::table('projektet') -> where('klubi', '=',$id);

From:

$dataOfProjects = DB::table('projektet') -> where('klubi', '=',$id);

To (for multiple results):

$dataOfProjects = DB::table('projektet')->where('klubi', '=',$id)->get();

To (for one results):

$dataOfProjects = DB::table('projektet')->where('klubi', '=',$id)->first();
  • Related