Laravel Trying to get property of non-object Error

I have an error that I can not understand why this happened. I try to return a view but laravel looks for a different view that I didn't define. Another error is laravel looks for a variable I defined but undefined variable occurs. I think this happens because of laravel looks for undefined view.

This is my route. php code about that:

Route::get('/{kategori}', 'front\HaberController@kategori' ); 
Route::get('/{kategori}/{haber}/{id}', 'front\HaberController@haber' );

And this is my function in the HaberController

public function haber( $kategoriSlug = "Genel", $haberSlug , $id = 0 )
{
    GoruntulenmeSayaci::sayaciArtir( $this->haberVeriTuruId, $id ) ;
    if( Cache::has( 'haberDetay'.$id ) ){
        return Cache::get( 'haberDetay'.$id );
    } else {
            if( $id != 0 && is_numeric( $id ) ){
                if( isset ( session('yetki')->haber ) && session('yetki')->haber  > 1 ){  
                    $haber = DB::table('haberler')->where( "id", $id )->first(); 
                }else{
                    $haber = DB::table('haberler')->where( "id", $id )->where( "aktif_pasif", 1 )->first(); 
                }

            }else{
                return false;       
            }

            $anasayfaUstKutu = self::getAnasayfaUstKutu();
            $anasayfaSlider = self::getAnasayfaSlider();
            $kategori = DB::table('kategoriler')->where( "slug", $kategoriSlug )->where( "veri_turu_id", $this->haberVeriTuruId )->first(); 
            $anasayfaGrid = self::getAnasayfaGrid();
            $anasayfaVideolar = self::getAnasayfaVideolar();
            $anasayfaGaleriler = self::getAnasayfaGaleriler();
            $reklamlar = self::getReklamlar();
            $sonuc = view("front.haber.detay", [  
                                                "anasayfaUstKutu" => $anasayfaUstKutu, 
                                                "anasayfaSlider" => $anasayfaSlider, 
                                                "anasayfaVideolar" => $anasayfaVideolar,
                                                "anasayfaGaleriler" => $anasayfaGaleriler,
                                                "anasayfaGrid" => $anasayfaGrid,
                                                "haber" => $haber,
                                                "kategori" => $kategori,
                                                "reklamlar" => $reklamlar


                                             ]);



Cache::put( 'haberDetay'.$id , $sonuc->render(), $this->cacheSuresi );
            return $sonuc;
    }
}

When I try these codes laravel gives this error:

Undefined variable: reklamlar (View: /home/yazilim/resources/views/front/haber/kategori.blade.php)

Upvotes: 1

Views: 441

Answers (2)

Claudio King
Claudio King

Reputation: 1616

First of all, check what value self::getReklamlar() returns, then if it is ok, try to edit the last lines of code like above.

$sonuc = view("front.haber.detay", [  
    "anasayfaUstKutu" => $anasayfaUstKutu, 
    "anasayfaSlider" => $anasayfaSlider, 
    "anasayfaVideolar" => $anasayfaVideolar,
    "anasayfaGaleriler" => $anasayfaGaleriler,
    "anasayfaGrid" => $anasayfaGrid,
    "haber" => $haber,
    "kategori" => $kategori,
    "reklamlar" => $reklamlar  
 ])->render();



Cache::put('haberDetay'.$id , $sonuc, $this->cacheSuresi);

return $sonuc;

Upvotes: 0

Demian
Demian

Reputation: 390

The variable 'reklamlar' is not found in your kategori.blade.php file.

Where do you make the view? Are you giving the variable with the view?

E.g.

return View::make('front.haber.kategori')->with('reklamar', null);

Upvotes: 1

Related Questions