The routes/web.php
have common application routes, Like showing the views, Getting the data from the form to a controller method.
The routes/api.php
will have routes for getting records of the tables/entities in JSON
. Updating, Deleting etc via api routes ?
Question 1 : How will i use my routes/api.php
routes to get, delete, Update data/Records ?
Question 2 : Android app will be able to use my api ? If yes, How ?
Question 3 : The API should have a controller ApiController
?
Let the kid know the stuff !
Thanks
Put this into your RouteServiceProvider
file:
$router->group(['namespace' => $this->webNamespace], function ($router) {
require app_path('routes/web.php');
});
$router->group(['namespace' => $this->apiNamespace], function ($router) {
require app_path('routes/api.php');
});
require_once "../../routes/api.php";
yes. use your routes as you would use them in any other frontend application. For example: localhost/api/myAndroidRoute
doesn't really matter. you can use one controller for all the routes, or one controller for each route. Whichever option you like. If you have a lot of code, separate it into different controllers for better readibility. For example:
Route::get('api/sampledata', 'ApiController@getSampleData'); // controller@function
Route::get('api/otherdata', 'SomeOtherController@getOtherData');
or
Route::get('api/sampledata', 'AllmightyController@getSampleData');
Route::get('web/otherdata', 'AllmightyController@getOtherData');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.