phpvms/app/Http/Controllers/Api/UserController.php

55 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\Api;
2018-01-03 04:37:52 +08:00
use Auth;
use Illuminate\Http\Request;
use App\Repositories\UserRepository;
use App\Models\UserBid;
use App\Http\Resources\Flight as FlightResource;
use App\Http\Resources\User as UserResource;
class UserController extends RestController
{
protected $userRepo;
public function __construct(UserRepository $userRepo)
{
$this->userRepo = $userRepo;
}
/**
* Return the profile for the currently auth'd user
*/
public function index(Request $request)
{
UserResource::withoutWrapping();
2018-01-03 04:37:52 +08:00
return new UserResource(Auth::user());
}
/**
* Get the profile for the passed-in user
*/
public function get($id)
{
UserResource::withoutWrapping();
return new UserResource($this->userRepo->find($id));
}
/**
* Return all of the bids for the passed-in user
*/
public function bids($id)
{
$flights = UserBid::where(['user_id' => $id])->get()
->pluck('flight');
return FlightResource::collection($flights);
}
}