mercredi 29 mai 2019

Undefined variable: data in laravel

Undefined variable: data error occure when i want to display data from database. here is my code

//Controller
public function filter(Request $request)
    {

        $data = Trial::where('zipcode',$request->zipcode)->select('lat','lng')->first(); 
        $lat = $data->lat;
        $lng = $data->lng;
        $distance = 5 ;// Diatanse in kms
        $query = Trial::getByDistance($lat, $lng, $distance); 

        $ids = []; 
                //Extract the id's
            if(!empty($query)) {
            foreach($query as $q)
            {
                array_push($ids, $q->id);
            }
            }

            // Now write final query 
            if(!empty($ids)){
                $results = DB::table('trial')->whereIn( 'id', $ids)->where('zipcode'); 
            }

        return view('search.searchhome',compact('data',$data));
        dd($data);

    }
// Blade
<p>
                        @foreach($data as $dat)
                            
                        @endforeach

                     </p>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire