Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem to get laravel api route and that always get in laravel.blade.php as xhr(html) #31

Closed
heidaryBhnam opened this issue Apr 9, 2019 · 5 comments

Comments

@heidaryBhnam
Copy link

heidaryBhnam commented Apr 9, 2019

Hi
Thank you for your Great work. That's very good.

So i have problem to get a laravel controller as a api. i try any ways for one weekend and so dissapointed. now i have one table name 'personal' is migrated true. that's have controller named 'app/Http/controllers/Api/PersonalController' and there class is 'app/Personal' and the resource are 'app/Http/Resources/PersonalCollection'. inside 'route/api.php' controller are routed true.
that's have on command 'php artisan route:list' true. so inside 'resources/js/api/tabel.js' i add the below code:
export function getPersonal() { return request({ url: '/personal', method: 'get', }); }
then create a vue component for test it like this:

index

so after run server and 'npm run watch' inside browser console have an error say TypeError: response.data is undefined and inside browser network personal are loaded as xhr couses and html type. that's header are passed OK but in Response are loaded laravue default page.
this page are routed on 'route/web.php' as {any}

i try other way like SPA, direct request, loaded axios inside component and etc but all wayes return this problem.

@diegodcl
Copy link

Hi Marmulack. I digged to find that out too. All the requests are redirected to \vendor\tuandm\laravue-core\src\routes\laravue.php. You find all the routes in this file. ou can implement yours there as well

@tuandm
Copy link
Owner

tuandm commented Apr 10, 2019

Hi @marmulack, thanks for reaching this project
With the current code base, you have to define api routers in api.php (or tuandm/laravue-core/src/routers/laravue.php). You can double check by php artisan route:list to see if your API URL is there.

We are preparing the docs to describe how to working with API in Laravue.

@heidaryBhnam
Copy link
Author

thank's for your fast awnser @tuandm

thephp artisan route:list worked true when define routes in api.php. but working like before and my route list are like this:
route_list
so i try to Manipulation to change tuandm/laravue-core/src/routers/laravue.php as added below code:

$app_namespace = app_path('Http\controllers');

Route::group(['namespace' => $app_namespace, 'prefix' => 'api', 'middleware' => 'api'], function () {
Route::get('/personal', 'PersonalsController@index');
});

and route PersonalsController@index inside api.php too. so worked true, problem is solved but this is not good to Repeat every controller route inside tuandm/laravue-core/src/routers/laravue.php too. are better to solved this problem too for easier coding.

@tuandm
Copy link
Owner

tuandm commented Apr 10, 2019

@marmulack Yes, thanks for pointing the problem. Next release of Laravue will remove routes in Laravel's package (tuandm/laravue-core...), and use default Laravel web.php/api.php instead. It will help users custom the routers by their way.

@tuandm
Copy link
Owner

tuandm commented Apr 16, 2019

#33

@tuandm tuandm closed this as completed Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants