#57 user can save flights
This commit is contained in:
@@ -7,6 +7,8 @@ use Illuminate\Support\Facades\Auth;
|
||||
use App\Repositories\FlightRepository;
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
|
||||
use App\Models\UserFlight;
|
||||
use Mockery\Exception;
|
||||
|
||||
class FlightController extends AppBaseController
|
||||
{
|
||||
@@ -29,29 +31,68 @@ class FlightController extends AppBaseController
|
||||
// TODO: PAGINATION
|
||||
|
||||
$flights = $this->flightRepo->findWhere($where);
|
||||
$saved_flights = UserFlight::where('user_id', Auth::id())
|
||||
->pluck('flight_id')->toArray();
|
||||
|
||||
return $this->view('flights.index', [
|
||||
'flights' => $flights,
|
||||
'saved' => $saved_flights,
|
||||
]);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
public function search(Request $request)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function search(Request $request) {
|
||||
$where = ['active' => true];
|
||||
$flights = $this->flightRepo->findWhere($where);
|
||||
|
||||
// TODO: PAGINATION
|
||||
|
||||
$saved_flights = UserFlight::where('user_id', Auth::id())
|
||||
->pluck('flight_id')->toArray();
|
||||
|
||||
return $this->view('flights.index', [
|
||||
'flights' => $flights,
|
||||
'saved' => $saved_flights,
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$user_id = Auth::id();
|
||||
$flight_id = $request->input('flight_id');
|
||||
$action = $request->input('action');
|
||||
|
||||
$cols = ['user_id' => $user_id, 'flight_id' => $flight_id];
|
||||
|
||||
if(strtolower($action) == 'save') {
|
||||
$uf = UserFlight::create($cols);
|
||||
$uf->save();
|
||||
|
||||
return response()->json([
|
||||
'id' => $uf->id,
|
||||
'message' => 'Saved!',
|
||||
]);
|
||||
}
|
||||
|
||||
elseif (strtolower($action) == 'remove') {
|
||||
try {
|
||||
$uf = UserFlight::where($cols)->first();
|
||||
$uf->delete();
|
||||
} catch (Exception $e) { }
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Deleted!'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user