500 http error - AJAX

Posted 1 year ago by jozenaiser

Hello guys.

I'm having some problems at updating a model via ajax.

If I comment the specific line where I save the model ($tag->save()), no error is thrown, but once I uncomment it, I get that error which has been driving me crazy.

Can somebody help me?

This is the code:

public function edit(Request $request) {

    $this->validate($request, [
        'name' => 'required|max:75',
    ]);
    if($request->ajax()) {
        $tag = Tag::find($request->id);
        $tag->name = $request->name;
        $tag->save();

        if($request->type == 'hashtag') {
            Session::flash('message', 'Se ha actualizado correctamente el hashtag!');   
        }else{
            Session::flash('message', 'Se ha actualizado correctamente la categoria!');
        }
        return response()->json(['status' => 'ok']);
    }else{
        return redirect()->back();
    }
     return response()->json(['status' => 'ok']);

}

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.