xdega
376
10
Laravel

Errors when trying to update via HTTP route.

Posted 2 years ago by xdega

So. First off. I have the following method in a Resource Controller:

    public function update(Request $request, $id){

        //Validation Logic
        $this->validate($request, [
            'avatar' => 'min:3|alpha'
        ]);

        Profile::findOrFail($id)->update($request->all());

        return Profile::json($request->all()); //response()->json()

    }

And I am making the following call via a vue component + axios:

            updateAvatar: function() {

                var payload = {'avatar':this.newAvatar}
                axios.put('api/profiles/' + this.profileID, payload)
                    .then( this.onSuccess() )
                    .catch( error => this.errors );
            },

When I submit the request, I get one of two responses.

The first one (seemingly when the validation passes, and db actually updates) is:

BadMethodCallException in Builder.php line 2508:
Call to undefined method Illuminate\Database\Query\Builder::json()

the second error (seemingly when the validation fails) is: MethodNotAllowedHttpException in RouteCollection.php line 233:

This is working inasmuch as it updates the DB if validation passes, but totally broken behind the scenes.

I, obviously need to be able to access a response that gives me errors from the update itself.

Can anyone help shed a light on what might be going on here?

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