jeudi 28 décembre 2017

Call function inside other function

Can't seem to figure out how to call other function inside function, if that makes sense.

public function createcat()
    {
        $kat_id = kategorijas::find('id');
        $apakskat = apakskategorijas::where('kategorijas_id','=',$kat_id)->get();
        $kat = kategorijas::with('apakskategorija')->get(); 
        //$list = compact('kat','apakskat','apakskat_count');

    }
    public function mainpage()
    {
        // $kat_id = kategorijas::find('id');
        // $apakskat = apakskategorijas::where('kategorijas_id','=',$kat_id)->get();
        // $kat = kategorijas::with('apakskategorija')->get(); 
        $list = $this->createcat();     
        return view ('views.home',compact('list'));
    }

The thing is, that other views need createcat function to work, otherwise it shows errors that view doesn't have variables that are in createcat function.

Is this even good practice? Or the createcat function should be created elsewhere and called from certain place?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire