Remove empty fields from user return, add avatar
This commit is contained in:
@@ -3,32 +3,36 @@
|
|||||||
namespace App\Http\Resources;
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
use App\Contracts\Resource;
|
use App\Contracts\Resource;
|
||||||
|
use App\Http\Resources\Flight as FlightResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @mixin \App\Models\User
|
||||||
|
*/
|
||||||
class User extends Resource
|
class User extends Resource
|
||||||
{
|
{
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
return [
|
$res = [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'pilot_id' => $this->pilot_id,
|
'pilot_id' => $this->pilot_id,
|
||||||
|
'avatar' => $this->avatar,
|
||||||
'ident' => $this->ident,
|
'ident' => $this->ident,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'apikey' => $this->apikey,
|
|
||||||
'rank_id' => $this->rank_id,
|
'rank_id' => $this->rank_id,
|
||||||
'home_airport' => $this->home_airport_id,
|
'home_airport' => $this->home_airport_id,
|
||||||
'curr_airport' => $this->curr_airport_id,
|
'curr_airport' => $this->curr_airport_id,
|
||||||
'last_pirep_id' => $this->last_pirep_id,
|
'last_pirep_id' => $this->last_pirep_id,
|
||||||
'flights' => $this->flight,
|
|
||||||
'flight_time' => $this->flight_time,
|
'flight_time' => $this->flight_time,
|
||||||
'balance' => $this->balance,
|
|
||||||
'timezone' => $this->timezone,
|
'timezone' => $this->timezone,
|
||||||
'status' => $this->status,
|
|
||||||
'state' => $this->state,
|
'state' => $this->state,
|
||||||
|
'rank' => Rank::make($this->rank),
|
||||||
'airline' => Airline::make($this->airline),
|
|
||||||
'bids' => UserBid::collection($this->bids),
|
|
||||||
'rank' => Rank::make($this->rank),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$res['airline'] = Airline::make($this->airline);
|
||||||
|
$res['bids'] = UserBid::collection($this->whenLoaded('bids'));
|
||||||
|
$res['flights'] = new FlightResource($this->whenLoaded('flights'));
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use Laratrust\Traits\LaratrustUserTrait;
|
|||||||
* @property string ident
|
* @property string ident
|
||||||
* @property string curr_airport_id
|
* @property string curr_airport_id
|
||||||
* @property string home_airport_id
|
* @property string home_airport_id
|
||||||
|
* @property string avatar
|
||||||
* @property Airline airline
|
* @property Airline airline
|
||||||
* @property Flight[] flights
|
* @property Flight[] flights
|
||||||
* @property int flight_time
|
* @property int flight_time
|
||||||
@@ -142,7 +143,7 @@ class User extends Authenticatable
|
|||||||
public function getAvatarAttribute()
|
public function getAvatarAttribute()
|
||||||
{
|
{
|
||||||
if (!$this->attributes['avatar']) {
|
if (!$this->attributes['avatar']) {
|
||||||
return;
|
return $this->gravatar();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new File([
|
return new File([
|
||||||
|
|||||||
@@ -263,4 +263,12 @@ class ApiTest extends TestCase
|
|||||||
$res = $this->get('/api/settings')->assertStatus(200);
|
$res = $this->get('/api/settings')->assertStatus(200);
|
||||||
$settings = $res->json();
|
$settings = $res->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetUser()
|
||||||
|
{
|
||||||
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
|
$res = $this->get('/api/user')->assertStatus(200);
|
||||||
|
$user = $res->json('data');
|
||||||
|
$this->assertNotNull($user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user