0
Through Composer, I started a project with the command:
composer create-project --prefer-dist laravel/laravel api
After the installation of the dependencies, I was able to visualize the "Welcome" of the application (Through the standard wheel that is already created at the time of project startup).
In the wheel file, inside the directory route
the file web.php
, there is the code:
Route::get('/', function () {
return view('welcome');
});
So far so good, that even though the application was created correctly, only that I have no interest in making the web application by the Laravel, I just want to use the api Laravel, for this:
Inside the directory route
in the archive api.php
:
Route::get('/', function () {
return 'API';
});
The paths to access the api should remain, however regardless of the route I configure in this file (api.php) is not processed by the application, the following error appears when I access the link http://localhost/api/public/api
:
What I might have done wrong, because I can’t access the api routes?
try only
localhost/api
. No need to place localhost/<project>/public name to access your endpoints (whereas you have set Laravel correctly to be the webserver root)– gmsantos
@gmsantos did not configure anything, I think just put the routes in the api.php file and everything will work. To answer you: it doesn’t work, I try in life that I have several projects within the localhost, so this Laravel project is just another folder. From what you said I think I need to set something up..
– Milrak Pereira Pessoa
Updates to the Laravel 5.6 that goes perfect.
– Eduardo F G
I updated and the error persisted, I deleted the project and ran the command again, it worked! I think there may have been some problem at the time the script was running.
– Milrak Pereira Pessoa