samedi 11 novembre 2017

Method hospitals does not exist

Hey I am working on a project in which i have defined many to many relation between two tables. I have made a method in model class but whenever i call that method from my controller it gives me error method does not exist. Below is my code of controller and model.

Controller

   if($request->hospitalId != null)
    {
        $IdArray = explode(',', $request->hospitalId);
        $doc= DB::table('doctors')->where('doctorId', $request->doctorId)->get();
        foreach ($IdArray as $Id) {
            $doc->hospitals()->attach($Id);
        }
    }

And model is

 public function hospitals()
{
    return $this->belongsToMany('App\Hospital');
}

Please let me know what I am doing wrong in it.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2yRc0hI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire