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