0

I'm trying to create a custom function for a Controller class that I'm using as ResourceController. I'm doing it cause I only want to update 1 field, but I want to keep the existing update function for other things.

I've tried to put it before the resource in the api.php as people said but still no good.

Route::put('/post/reorder/{id}', 'PostController@reorder');
Route::resource('/post', PostController::class);

This is the code in the controller

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

        $post = Post::findOrfail($id);
...

Also, when running php artisan route:list it shows this error.

   Illuminate\Contracts\Container\BindingResolutionException

  Target class [PostController] does not exist.

This is the code in VUE that's calling it

export const API_URL = "http://localhost:8000/api/post";

axios
        .put(API_URL + `/reorder/${item.id}`, {
          // title: item.title,
          // path: item.path,
          // description: item.description,
          order: newIndex,
        })

And when I run it, it gives the Internal Server Error 500

It works when I'm using the default function that resource gave me, I just don't want to have to input the fields I don't want to change.

So what did I do wrong?

1 Answer 1

1

i think you are using laravel8 and your route is not correct

try this:

Route::put('/post/reorder/{id}', [PostController::class, 'reorder']);
Sign up to request clarification or add additional context in comments.

1 Comment

Urgh yea okay, apparently it's just that. Works fine now. Thanks!

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.