0
votes

Laravel 5.8 only return the view of SPA for any route.

Iam building a crud with Laravel 5.8 + vue and I want to define 2 routes in routes/web.php the first route return SPA vue app the second instead it returns a collection of new App\User instances.

When I try call crud.test/users laravel return SPA crud again and the second route never execute.

But If I remove the first route crud.test/users works.

Route::get('{path}', function () {
  return view('spa');
})->where('path', '(.*)');


Route::get('/users', function () {
  return factory('App\User', 10)->make();
});

I expect to laravel returnme array of 10 Users

1

1 Answers

0
votes

You are putting a wild card : {path} to catch all requests in the first route!

try to put the /users route first:

Route::get('/users', function () {
  return factory('App\User', 10)->make();
});

Route::get('{path}', function () {
  return view('spa');
})->where('path', '(.*)');