Rename 'Airlines' model to 'Airline'

This commit is contained in:
Nabeel Shahzad 2017-06-19 11:50:25 -05:00
parent 6ef83084d1
commit c732476f6d
19 changed files with 94 additions and 84 deletions

View File

@ -2,9 +2,9 @@
namespace App\Http\Controllers\Admin;
use App\Http\Requests\CreateAirlinesRequest;
use App\Http\Requests\UpdateAirlinesRequest;
use App\Repositories\AirlinesRepository;
use App\Http\Requests\CreateAirlineRequest;
use App\Http\Requests\UpdateAirlineRequest;
use App\Repositories\AirlineRepository;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
@ -12,12 +12,12 @@ use Response;
class AirlinesController extends BaseController
{
/** @var AirlinesRepository */
private $airlinesRepository;
/** @var AirlineRepository */
private $airlineRepo;
public function __construct(AirlinesRepository $airlinesRepo)
public function __construct(AirlineRepository $airlinesRepo)
{
$this->airlinesRepository = $airlinesRepo;
$this->airlineRepo = $airlinesRepo;
}
/**
@ -25,8 +25,8 @@ class AirlinesController extends BaseController
*/
public function index(Request $request)
{
$this->airlinesRepository->pushCriteria(new RequestCriteria($request));
$airlines = $this->airlinesRepository->all();
$this->airlineRepo->pushCriteria(new RequestCriteria($request));
$airlines = $this->airlineRepo->all();
return view('admin.airlines.index')
->with('airlines', $airlines);
@ -43,10 +43,10 @@ class AirlinesController extends BaseController
/**
* Store a newly created Airlines in storage.
*/
public function store(CreateAirlinesRequest $request)
public function store(CreateAirlineRequest $request)
{
$input = $request->all();
$airlines = $this->airlinesRepository->create($input);
$airlines = $this->airlineRepo->create($input);
Flash::success('Airlines saved successfully.');
@ -62,7 +62,7 @@ class AirlinesController extends BaseController
*/
public function show($id)
{
$airlines = $this->airlinesRepository->findWithoutFail($id);
$airlines = $this->airlineRepo->findWithoutFail($id);
if (empty($airlines)) {
Flash::error('Airlines not found');
@ -81,7 +81,7 @@ class AirlinesController extends BaseController
*/
public function edit($id)
{
$airlines = $this->airlinesRepository->findWithoutFail($id);
$airlines = $this->airlineRepo->findWithoutFail($id);
if (empty($airlines)) {
Flash::error('Airlines not found');
@ -95,20 +95,20 @@ class AirlinesController extends BaseController
* Update the specified Airlines in storage.
*
* @param int $id
* @param UpdateAirlinesRequest $request
* @param UpdateAirlineRequest $request
*
* @return Response
*/
public function update($id, UpdateAirlinesRequest $request)
public function update($id, UpdateAirlineRequest $request)
{
$airlines = $this->airlinesRepository->findWithoutFail($id);
$airlines = $this->airlineRepo->findWithoutFail($id);
if (empty($airlines)) {
Flash::error('Airlines not found');
return redirect(route('airlines.index'));
}
$airlines = $this->airlinesRepository->update($request->all(), $id);
$airlines = $this->airlineRepo->update($request->all(), $id);
Flash::success('Airlines updated successfully.');
@ -124,14 +124,14 @@ class AirlinesController extends BaseController
*/
public function destroy($id)
{
$airlines = $this->airlinesRepository->findWithoutFail($id);
$airlines = $this->airlineRepo->findWithoutFail($id);
if (empty($airlines)) {
Flash::error('Airlines not found');
return redirect(route('airlines.index'));
}
$this->airlinesRepository->delete($id);
$this->airlineRepo->delete($id);
Flash::success('Airlines deleted successfully.');

View File

@ -3,9 +3,9 @@
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\Airlines;
use App\Models\Airline;
class CreateAirlinesRequest extends FormRequest
class CreateAirlineRequest extends FormRequest
{
/**
@ -25,6 +25,6 @@ class CreateAirlinesRequest extends FormRequest
*/
public function rules()
{
return Airlines::$rules;
return Airline::$rules;
}
}

View File

@ -3,9 +3,9 @@
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\Airlines;
use App\Models\Airline;
class UpdateAirlinesRequest extends FormRequest
class UpdateAirlineRequest extends FormRequest
{
/**
@ -25,6 +25,6 @@ class UpdateAirlinesRequest extends FormRequest
*/
public function rules()
{
return Airlines::$rules;
return Airline::$rules;
}
}

View File

@ -6,10 +6,10 @@ use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Airlines
* Class Airline
* @package App\Models
*/
class Airlines extends Model
class Airline extends Model
{
use SoftDeletes;

View File

@ -63,6 +63,12 @@ class Flight extends Model
'arr_airport_id' => 'required',
];
public function airline()
{
return $this->belongsTo('App\Models\Airline',
'airline_id');
}
public function dpt_airport()
{
return $this->belongsTo('App\Models\Airport', 'dpt_airport_id');

View File

@ -2,9 +2,9 @@
namespace App\Repositories;
use App\Models\Airlines;
use App\Models\Airline;
class AirlinesRepository extends BaseRepository
class AirlineRepository extends BaseRepository
{
/**
* @var array
@ -19,6 +19,6 @@ class AirlinesRepository extends BaseRepository
**/
public function model()
{
return Airlines::class;
return Airline::class;
}
}

View File

@ -1,10 +0,0 @@
<?php
$factory->define(App\Models\AircraftClass::class, function (Faker\Generator $faker) {
return [
'id' => 1,
'code' => 'H',
'name' => 'Heavy',
'notes' => 'Heavy aircraft',
];
});

View File

@ -1,10 +0,0 @@
<?php
$factory->define(App\Models\Fare::class, function (Faker\Generator $faker) {
return [
'code' => 'Y',
'name' => 'Economy',
'price' => '100',
'capacity' => '200',
];
});

View File

@ -1,10 +0,0 @@
<?php
$factory->define(App\Models\Flight::class, function (Faker\Generator $faker) {
return [
'code' => 'Y',
'name' => 'Economy',
'price' => '100',
'capacity' => '200',
];
});

View File

@ -12,7 +12,35 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
$this->seed_from_yaml(App::environment());
}
protected function seed_from_yaml($env): void
{
$path = database_path('seeds/'.$env.'.yml');
$time_fields = ['created_at', 'updated_at'];
$curr_time = Carbon::now('UTC')->format('Y-m-d H:i:s');
$yml = Yaml::parse(file_get_contents($path));
foreach ($yml as $table => $rows) {
foreach ($rows as $row) {
# encrypt any password fields
if (array_key_exists('password', $row)) {
$row['password'] = bcrypt($row['password']);
}
# if any time fields are == to "now", then insert the right time
foreach ($time_fields as $tf) {
if (array_key_exists($tf, $row) && $row[$tf] === 'now') {
$row[$tf] = $curr_time;
}
}
DB::table($table)->insert($row);
}
}
}
}

View File

@ -12,7 +12,7 @@
<div class="box-body">
<div class="row">
{!! Form::open(['route' => 'airlines.store']) !!}
{!! Form::open(['route' => 'admin.airlines.store']) !!}
@include('admin.airlines.fields')

View File

@ -11,7 +11,7 @@
<div class="box box-primary">
<div class="box-body">
<div class="row">
{!! Form::model($airlines, ['route' => ['airlines.update', $airlines->id], 'method' => 'patch']) !!}
{!! Form::model($airlines, ['route' => ['admin.airlines.update', $airlines->id], 'method' => 'patch']) !!}
@include('admin.airlines.fields')

View File

@ -22,5 +22,5 @@
<!-- Submit Field -->
<div class="form-group col-sm-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{!! route('airlines.index') !!}" class="btn btn-default">Cancel</a>
<a href="{!! route('admin.airlines.index') !!}" class="btn btn-default">Cancel</a>
</div>

View File

@ -4,7 +4,7 @@
<section class="content-header">
<h1 class="pull-left">Airlines</h1>
<h1 class="pull-right">
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('airlines.create') !!}">Add New</a>
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('admin.airlines.create') !!}">Add New</a>
</h1>
</section>
<div class="content">

View File

@ -11,7 +11,7 @@
<div class="box-body">
<div class="row" style="padding-left: 20px">
@include('admin.airlines.show_fields')
<a href="{!! route('airlines.index') !!}" class="btn btn-default">Back</a>
<a href="{!! route('admin.airlines.index') !!}" class="btn btn-default">Back</a>
</div>
</div>
</div>

View File

@ -12,10 +12,10 @@
<td>{!! $al->name !!}</td>
<td>{!! $al->active !!}</td>
<td>
{!! Form::open(['route' => ['airlines.destroy', $al->id], 'method' => 'delete']) !!}
{!! Form::open(['route' => ['admin.airlines.destroy', $al->id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{!! route('airlines.show', [$al->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
<a href="{!! route('airlines.edit', [$al->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
<a href="{!! route('admin.airlines.show', [$al->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
<a href="{!! route('admin.airlines.edit', [$al->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
</div>
{!! Form::close() !!}

View File

@ -3,7 +3,6 @@
<th>Flight #</th>
<th>Dep</th>
<th>Arr</th>
<th>Alt</th>
<th>Route</th>
<th>Dpt Time</th>
<th>Arr Time</th>
@ -15,12 +14,18 @@
@foreach($flights as $flight)
<tr>
<td>
{!! $flight->airline_id !!}/{!! $flight->flight_number !!}
(C: {!! $flight->route_code !!} L: {!! $flight->route_leg !!})
{!! $flight->airline->code !!}{!! $flight->flight_number !!}
@if($flight->route_code)
(C: {!! $flight->route_code !!} L: {!! $flight->route_leg !!})
@endif
</td>
<td>{!! $flight->dpt_airport->icao !!}</td>
<td>{!! $flight->arr_airport->icao !!}</td>
<td>{!! $flight->alt_airport->icao !!}</td>
<td>
{!! $flight->arr_airport->icao !!}
@if($flight->alt_airport)
(Alt: {!! $flight->alt_airport->icao !!})
@endif
</td>
<td>{!! $flight->route !!}</td>
<td>{!! $flight->dpt_time !!}</td>
<td>{!! $flight->arr_time !!}</td>

View File

@ -9,17 +9,7 @@ class AircraftTest extends TestCase
public function setUp()
{
parent::setUp();
$this->setup_data();
}
/**
* add the fares to a given aircraft
* run the factory for incl the fares
*/
protected function setup_data()
{
factory(App\Models\AircraftClass::class)->create();
factory(App\Models\Fare::class)->create();
$this->addData('aircraft_test');
}
protected function getAircraftClass()

View File

@ -0,0 +1,11 @@
aircraft_classes:
- id: 1
code: H
name: Heavy
notes: Heavy Aircraft
fares:
- code: Y
name: Economy
price: 100
capacity: 200