1

I can insert, update and delete in Laravel for sure but I don't know why in this case i get stuck, so please share your mind here. here was my function

public function hapuskeluhan($id){

    $keluh = keluhan::findOrFail($id);
    $tindak = tindakan::where('id_keluhan',$id)->get();
    $analisa = analisa::join('tindakans','tindakans.id','=','analisas.id_tindakan')
    ->join('keluhans','keluhans.id','=','tindakans.id_keluhan')
    ->where('keluhans.id','=',$id)->get();
    //dd($analisa);

    $keluh->delete();
    $tindak->delete();
    $analisa->delete();
    \Session::flash('flash_message','Data successfully deleted.');
    return redirect('lihatkeluhan');
}

i got error when delete $analisa... please kindly help

8
  • 3
    why use join for delete?? how can laravel know which record of the two you joined to delete? Commented Apr 5, 2017 at 7:34
  • check this for join delete in laravel: stackoverflow.com/questions/23802662/… Commented Apr 5, 2017 at 7:47
  • If you're going to use eloquent then you should not join, you should define relationships and then select a model on condition of those relationships. Eloquent will sort things out for you if you do that. Commented Apr 5, 2017 at 8:08
  • How are your models defined? Commented Apr 5, 2017 at 8:15
  • 1
    @ChristianusAndre read laravel.com/docs/5.4/eloquent-relationships . All of it. Don't skim through it. Read it. Commented Apr 5, 2017 at 8:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.