0
votes

I'm getting the following error:

GET http://backend.test/test?last_name=DOE 404 (Not Found)

When trying the following GET method:

My GET request in Vue.JS:

    testMethod: _.debounce(async function () {
      await axios.get('test', { params: { last_name: 'DOE' } })
        .then((response) => {
          console.log(response);
        })
        .catch((error) => {
          console.log(error);
        });
    }, 50),

The route in Laravel:

Route::get('test/{params}', 'TestController@filter');

The method in my Laravel's TestController.php (not passed):

    public function filter($params)
    {
        Log::info($params);
    }

What's wrong with it ?

=== EDIT ===

If I rewrite the route like this:

Route::get('test/{params?}', 'TestController@filter');

Then I get the following error in Laravel logs:

[2020-04-26 21:28:48] local.ERROR: Too few arguments to function App\Http\Controllers\TestController::filter(), 0 passed and exactly 1 expected {"userId":1,"exception":"[object] (ArgumentCountError(code: 0): Too few arguments to function App\Http\Controllers\TestController::filter(), 0 passed and exactly 1 expected at /Users/me/code/backend/app/Http/Controllers/TestController.php:10)

1
what does it say when you add ? to params like, {params?} - you are not sending params, just sending query string.Ersoy
@Ersoy I have just updated my post to reply your question.DevonDahon
Please update your controller method to accept Request to and remove params - and try to log with $request->toArray();Ersoy
That works perfect. Thanks a lot! Maybe you can post it as an answer ?DevonDahon
glad to hear that, i will post an answer, thanks.Ersoy

1 Answers

2
votes

Since Route::get('test/{params}', 'TestController@filter'); route expects params to be mandotary; adding ? to params will make it optional.

Route::get('test/{params?}', 'TestController@filter');

To fetch last_name, it is required to update controller method as following;

use Illuminate\Http\Request;

class TestController
{
    public function index(Request $request)
    {
        $request->get('last_name');
        // actions
    }
}