add Aircraft CRUD
This commit is contained in:
123
app/Http/Controllers/Admin/AircraftController.php
Normal file
123
app/Http/Controllers/Admin/AircraftController.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\CreateAircraftRequest;
|
||||
use App\Http\Requests\UpdateAircraftRequest;
|
||||
use App\Repositories\AircraftRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Flash;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
use Response;
|
||||
|
||||
class AircraftController extends AdminBaseController
|
||||
{
|
||||
/** @var AircraftRepository */
|
||||
private $aircraftRepository;
|
||||
|
||||
public function __construct(AircraftRepository $aircraftRepo)
|
||||
{
|
||||
$this->aircraftRepository = $aircraftRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the Aircraft.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->aircraftRepository->pushCriteria(new RequestCriteria($request));
|
||||
$aircraft = $this->aircraftRepository->all();
|
||||
|
||||
return view('admin.aircraft.index')
|
||||
->with('aircraft', $aircraft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new Aircraft.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('admin.aircraft.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created Aircraft in storage.
|
||||
*/
|
||||
public function store(CreateAircraftRequest $request)
|
||||
{
|
||||
$input = $request->all();
|
||||
|
||||
$aircraft = $this->aircraftRepository->create($input);
|
||||
|
||||
Flash::success('Aircraft saved successfully.');
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified Aircraft.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$aircraft = $this->aircraftRepository->findWithoutFail($id);
|
||||
|
||||
if (empty($aircraft)) {
|
||||
Flash::error('Aircraft not found');
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
|
||||
return view('admin.aircraft.show')->with('aircraft', $aircraft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified Aircraft.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$aircraft = $this->aircraftRepository->findWithoutFail($id);
|
||||
|
||||
if (empty($aircraft)) {
|
||||
Flash::error('Aircraft not found');
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
|
||||
return view('admin.aircraft.edit')->with('aircraft', $aircraft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified Aircraft in storage.
|
||||
*/
|
||||
public function update($id, UpdateAircraftRequest $request)
|
||||
{
|
||||
$aircraft = $this->aircraftRepository->findWithoutFail($id);
|
||||
|
||||
if (empty($aircraft)) {
|
||||
Flash::error('Aircraft not found');
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
|
||||
$aircraft = $this->aircraftRepository->update($request->all(), $id);
|
||||
|
||||
Flash::success('Aircraft updated successfully.');
|
||||
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified Aircraft from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$aircraft = $this->aircraftRepository->findWithoutFail($id);
|
||||
|
||||
if (empty($aircraft)) {
|
||||
Flash::error('Aircraft not found');
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
|
||||
$this->aircraftRepository->delete($id);
|
||||
|
||||
Flash::success('Aircraft deleted successfully.');
|
||||
|
||||
return redirect(route('admin.aircraft.index'));
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/CreateAircraftRequest.php
Normal file
30
app/Http/Requests/CreateAircraftRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use App\Models\Aircraft;
|
||||
|
||||
class CreateAircraftRequest extends FormRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return Aircraft::$rules;
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/UpdateAircraftRequest.php
Normal file
30
app/Http/Requests/UpdateAircraftRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use App\Models\Aircraft;
|
||||
|
||||
class UpdateAircraftRequest extends FormRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return Aircraft::$rules;
|
||||
}
|
||||
}
|
||||
55
app/Models/Aircraft.php
Normal file
55
app/Models/Aircraft.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Eloquent as Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* Class Aircraft
|
||||
* @package App\Models
|
||||
* @version June 9, 2017, 1:06 am UTC
|
||||
*/
|
||||
class Aircraft extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
public $table = 'aircraft';
|
||||
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
|
||||
public $fillable = [
|
||||
'icao',
|
||||
'name',
|
||||
'full_name',
|
||||
'registration',
|
||||
'active'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'icao' => 'string',
|
||||
'name' => 'string',
|
||||
'full_name' => 'string',
|
||||
'registration' => 'string',
|
||||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $rules = [
|
||||
'icao' => 'required|max:4',
|
||||
'name' => 'required',
|
||||
'full_name' => 'required',
|
||||
'registration' => 'required',
|
||||
];
|
||||
}
|
||||
28
app/Repositories/AircraftRepository.php
Normal file
28
app/Repositories/AircraftRepository.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Aircraft;
|
||||
use InfyOm\Generator\Common\BaseRepository;
|
||||
|
||||
class AircraftRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldSearchable = [
|
||||
'icao',
|
||||
'name',
|
||||
'full_name',
|
||||
'registration',
|
||||
'active',
|
||||
];
|
||||
|
||||
/**
|
||||
* Configure the Model
|
||||
**/
|
||||
public function model()
|
||||
{
|
||||
return Aircraft::class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateAircraftsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('aircraft', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('icao');
|
||||
$table->string('name');
|
||||
$table->string('full_name')->nullable();
|
||||
$table->string('registration')->nullable();
|
||||
$table->boolean('active');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('aircraft');
|
||||
}
|
||||
}
|
||||
24
resources/views/admin/aircraft/create.blade.php
Normal file
24
resources/views/admin/aircraft/create.blade.php
Normal file
@@ -0,0 +1,24 @@
|
||||
@extends('admin.app')
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
Aircraft
|
||||
</h1>
|
||||
</section>
|
||||
<div class="content">
|
||||
@include('adminlte-templates::common.errors')
|
||||
<div class="box box-primary">
|
||||
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
{!! Form::open(['route' => 'admin.aircraft.store']) !!}
|
||||
|
||||
@include('admin.aircraft.fields')
|
||||
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
23
resources/views/admin/aircraft/edit.blade.php
Normal file
23
resources/views/admin/aircraft/edit.blade.php
Normal file
@@ -0,0 +1,23 @@
|
||||
@extends('admin.app')
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
Aircraft
|
||||
</h1>
|
||||
</section>
|
||||
<div class="content">
|
||||
@include('adminlte-templates::common.errors')
|
||||
<div class="box box-primary">
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
{!! Form::model($aircraft, ['route' => ['admin.aircraft.update', $aircraft->id], 'method' => 'patch']) !!}
|
||||
|
||||
@include('admin.aircraft.fields')
|
||||
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
38
resources/views/admin/aircraft/fields.blade.php
Normal file
38
resources/views/admin/aircraft/fields.blade.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<!-- ICAO Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('icao', 'ICAO:') !!}
|
||||
{!! Form::text('icao', null, ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<!-- Name Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('name', 'Name:') !!}
|
||||
{!! Form::text('name', null, ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<!-- Full Name Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('full_name', 'Full Name:') !!}
|
||||
{!! Form::text('full_name', null, ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<!-- Registration Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('registration', 'Registration:') !!}
|
||||
{!! Form::text('registration', null, ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<!-- Active Field -->
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('active', 'Active:') !!}
|
||||
<label class="checkbox-inline">
|
||||
{!! Form::hidden('active', false) !!}
|
||||
{!! Form::checkbox('active', '1', null) !!} 1
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Submit Field -->
|
||||
<div class="form-group col-sm-12">
|
||||
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
|
||||
<a href="{!! route('admin.aircraft.index') !!}" class="btn btn-default">Cancel</a>
|
||||
</div>
|
||||
23
resources/views/admin/aircraft/index.blade.php
Normal file
23
resources/views/admin/aircraft/index.blade.php
Normal file
@@ -0,0 +1,23 @@
|
||||
@extends('admin.app')
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1 class="pull-left">Aircraft</h1>
|
||||
<h1 class="pull-right">
|
||||
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('admin.aircraft.create') !!}">Add New</a>
|
||||
</h1>
|
||||
</section>
|
||||
<div class="content">
|
||||
<div class="clearfix"></div>
|
||||
|
||||
@include('flash::message')
|
||||
|
||||
<div class="clearfix"></div>
|
||||
<div class="box box-primary">
|
||||
<div class="box-body">
|
||||
@include('admin.aircraft.table')
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
19
resources/views/admin/aircraft/show.blade.php
Normal file
19
resources/views/admin/aircraft/show.blade.php
Normal file
@@ -0,0 +1,19 @@
|
||||
@extends('admin.app')
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
Aircraft
|
||||
</h1>
|
||||
</section>
|
||||
<div class="content">
|
||||
<div class="box box-primary">
|
||||
<div class="box-body">
|
||||
<div class="row" style="padding-left: 20px">
|
||||
@include('admin.aircraft.show_fields')
|
||||
<a href="{!! route('admin.aircraft.index') !!}" class="btn btn-default">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
48
resources/views/admin/aircraft/show_fields.blade.php
Normal file
48
resources/views/admin/aircraft/show_fields.blade.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<!-- Id Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('id', 'ID:') !!}
|
||||
<p>{!! $aircraft->id !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Icao Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('icao', 'ICAO:') !!}
|
||||
<p>{!! $aircraft->icao !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Name Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('name', 'Name:') !!}
|
||||
<p>{!! $aircraft->name !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Full Name Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('full_name', 'Full Name:') !!}
|
||||
<p>{!! $aircraft->full_name !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Registration Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('registration', 'Registration:') !!}
|
||||
<p>{!! $aircraft->registration !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Active Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('active', 'Active:') !!}
|
||||
<p>{!! $aircraft->active !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Created At Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('created_at', 'Created At:') !!}
|
||||
<p>{!! $aircraft->created_at !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Updated At Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('updated_at', 'Updated At:') !!}
|
||||
<p>{!! $aircraft->updated_at !!}</p>
|
||||
</div>
|
||||
|
||||
28
resources/views/admin/aircraft/table.blade.php
Normal file
28
resources/views/admin/aircraft/table.blade.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<table class="table table-responsive" id="aircrafts-table">
|
||||
<thead>
|
||||
<th>ICAO</th>
|
||||
<th>Name</th>
|
||||
<th>Registration</th>
|
||||
<th>Active</th>
|
||||
<th colspan="3">Action</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($aircraft as $ac)
|
||||
<tr>
|
||||
<td>{!! $ac->icao !!}</td>
|
||||
<td>{!! $ac->name !!}</td>
|
||||
<td>{!! $ac->registration !!}</td>
|
||||
<td>{!! $ac->active !!}</td>
|
||||
<td>
|
||||
{!! Form::open(['route' => ['admin.aircraft.destroy', $ac->id], 'method' => 'delete']) !!}
|
||||
<div class='btn-group'>
|
||||
<a href="{!! route('admin.aircraft.show', [$ac->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
|
||||
<a href="{!! route('admin.aircraft.edit', [$ac->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() !!}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
Reference in New Issue
Block a user