Hi,
I want to start a new project that is using Blade.
I was wondering if it makes sense to separate all the data fetching logic into some sort of API, so that in the future, if I ever need to fetch data with another frontend (React for example), i will have the same API.
For example, if right now I have a page that shows list of items:
public function itemsList(Request $request)
{
$items = DB::select(...); //
return view('items_list', ['items' => $items]);
}
I will have something like:
$items = // get it from another internal API
return view('items_list', ['items' => $items]);
So when I will use this API from within Laravel, it won't be another HTTP request, but just a call for a method (however, it will be the same method that the API uses). Then, in the future if I ever want to return the same data it will probably be somewhere in web.php under an /api prefix
Does it make sense? If so, what would be a good practice to do it? Where would I place all those API methods?
Thanks