I'm developing a website and REST API which are a part of the same project folder.
I've developed a REST api as below
URL: example.com/login
Type: POST
Request Body:
{
"credentials": {
"username":"dd",
"password":"dd"
},
"appInfo": {
"version": "1.0"
}
}
In the login method (UserController) I'm fetching the request body as below
json_decode(Request::instance()->getContent());
Now I'm developing a webpage and want to invoke this API from there. I'm using the below code (HomeController)
public function acceptlogin(Request $request) {
$data = array(
'credentials'=> array(
'username'=>$request->email,
'password'=>$request->pasword
),
'appInfo'=> array(
'version'=> "1.0"
)
);
$request1 = Request::create('example.com/login', 'POST', $data);
$response = Route::dispatch($request1);
}
I'm able to invoke the login api from the above code but the below code in the login method returns empty.
json_decode(Request::instance()->getContent());
Can you please suggest on how to invoke a local API (within the same project) in Laravel
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire