dimanche 1 octobre 2017

Delete Data From all tables using Load() Laravel 5.5

i am trying to delete Model from Model table and all of its comments from Comments table...my current code delete the model but not its comments from the other table...

Here is my destroy function

public function destroy(Request $request,CadModel $cadmodel)
    {
        $cadmodel->load('comments')->delete();
        $request->session()->flash('message.level', 'success');
        $request->session()->flash('message.content', 'File Deleted Successfully!');
        return redirect()->route('dashboard');
    }

Here is the relationship i defined in CadModel Laravel Model...

 public function comments()
    {
        return $this->hasMany(Comment::class);
    }

Please Reply and suggest me a solution to delete both..Model and its Comments



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

Aucun commentaire:

Enregistrer un commentaire