Skip to content

Instantly share code, notes, and snippets.

@alfelric
Created November 27, 2021 04:24
Show Gist options
  • Save alfelric/b41b9e695e02f834b9c81ac04b653efb to your computer and use it in GitHub Desktop.
Save alfelric/b41b9e695e02f834b9c81ac04b653efb to your computer and use it in GitHub Desktop.
Get User Detail Attribute
<?php
use Illuminate\Support\Facades\Http;
class User extends Model
{
protected $appends = ['user_detail'];
public function getUserDetailAttribute()
{
$userId = $this->user_id;
$endpoint = "http://localhost:8002/api/user/$userId";
$response = Http::acceptJson()->get($endpoint);
return $response->json();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment