Provider/AppServiceProvider.php
public function boot()
{
$client = new Client();
$request = $client->request('POST', '[url]http://192.168.53.27:1996/api/login/[/url]',
[
'form_params' => [
'user_name' => 'user',
'password' => 'pass',
]
]);
// echo $request->getStatusCode();
$res = json_decode($request->getBody(), true);
$token = $res['token'];
Cache::put('APP_API_KEY', $token, 86400);
}
//Cache e kaydet
Cache::put('APP_API_KEY', $token, 86400);
GuzzleController.php
public function getToken()
{
return Cache::get('APP_API_KEY');
}
GuzzleController.php
public function getToken()
{
return Cache::get('APP_API_KEY');
}
public function users()
{
$client = new Client();
$request = $client->request('POST', '[url]http://192.168.53.27:1996/api/users/[/url]', [
"headers" => [
"Accept" => "application/json",
'Authorization' => 'Bearer ' . $this->getToken(),
"Content-type" => "application/json"
]]);
return json_decode($request->getBody(), true);
}
//donen response
{
"id":6,
"username":"salo",
"password":"123",
"status":true,
"firstname":"oef",
"lastname":"dsf",
"isadmin":false,
"email":"jnj@fd.com"
}