I have made an API that returns json in Laravel. (routes/api.php)
Now I want to consume said API inside my web-side of the project (routes/web.php (including middleware), blade views etc.).
The current solution that I have is something like this:
public function register(Request $request) {
// password1 == password2 etc (form logic / validation)
$internal_request = Request::create($this->base_api_url . 'register', 'POST');
$internal_request->replace($request->input());
$response = Route::dispatch($internal_request);
}
Which "forwards" the request to the api counterpart to my api if the form is valid. But I have the feeling this is not really best practice or smart. Other routes except login and register use the api token stored in session to make the calls. they append the token "x-token" as a header to $internal_request. Is it better to do this in middleware? Is there some example of a best implementation somewhere?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2l7Va41
via IFTTT
Aucun commentaire:
Enregistrer un commentaire