Awards Administration

This commit is contained in:
Servetas George 2018-01-28 21:19:35 +02:00
parent e57f0cb234
commit 78724e981c
16 changed files with 456 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAwardsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('awards', function (Blueprint $table) {
$table->increments('id');
$table->string('title', 50);
$table->text('description', 50)->nullable();
$table->string('image', 255)->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('awards');
}
}

View File

@ -0,0 +1,143 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\CreateAwardRequest;
use App\Http\Requests\UpdateAwardRequest;
use App\Repositories\AwardRepository;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;
class AwardController extends BaseController
{
/** @var AwardRepository */
private $awardRepository;
public function __construct(AwardRepository $awardRepo)
{
$this->awardRepository = $awardRepo;
}
/**
* Display a listing of the Fare.
*
* @param Request $request
*
* @return Response
*/
public function index(Request $request)
{
$this->awardRepository->pushCriteria(new RequestCriteria($request));
$awards = $this->awardRepository->all();
return view('admin.awards.index')
->with('awards', $awards);
}
/**
* Show the form for creating a new Fare.
*
* @return Response
*/
public function create()
{
return view('admin.awards.create');
}
/**
* Store a newly created Fare in storage.
*
* @param CreateFareRequest $request
*
* @return Response
*/
public function store(CreateAwardRequest $request)
{
$input = $request->all();
$award = $this->awardRepository->create($input);
Flash::success('Award saved successfully.');
return redirect(route('admin.awards.index'));
}
/**
* Display the specified Fare.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
$fare = $this->awardRepository->findWithoutFail($id);
if (empty($award)) {
Flash::error('Award not found');
return redirect(route('admin.awards.index'));
}
return view('admin.awards.show')->with('award', $award);
}
/**
* Show the form for editing the specified Fare.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
$award = $this->awardRepository->findWithoutFail($id);
if (empty($award)) {
Flash::error('Award not found');
return redirect(route('admin.awards.index'));
}
return view('admin.awards.edit')->with('award', $award);
}
/**
* Update the specified Fare in storage.
*
* @param int $id
* @param UpdateFareRequest $request
*
* @return Response
*/
public function update($id, UpdateAwardRequest $request)
{
$award = $this->awardRepository->findWithoutFail($id);
if (empty($award)) {
Flash::error('Award not found');
return redirect(route('admin.awards.index'));
}
$award = $this->awardRepository->update($request->all(), $id);
Flash::success('Award updated successfully.');
return redirect(route('admin.awards.index'));
}
/**
* Remove the specified Fare from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
{
$award = $this->awardRepository->findWithoutFail($id);
if (empty($award)) {
Flash::error('Fare not found');
return redirect(route('admin.awards.index'));
}
$this->awardRepository->delete($id);
Flash::success('Fare deleted successfully.');
return redirect(route('admin.awards.index'));
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\Award;
class CreateAwardRequest 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 Award::$rules;
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\Award;
class UpdateAwardRequest 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 Fare::$rules;
}
}

18
app/Http/Resources/Award.php Executable file
View File

@ -0,0 +1,18 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class Award extends Resource
{
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'image' => $this->image,
];
}
}

38
app/Models/Award.php Executable file
View File

@ -0,0 +1,38 @@
<?php
namespace App\Models;
/**
* Class Award
*
* @package Award\Models
*/
class Award extends BaseModel
{
public $table = 'awards';
public $fillable = [
'title',
'description',
'image',
];
protected $casts = [
];
public static $rules = [
'title' => 'required',
];
/**
* any foreign keys
*/
/*
public function subfleets() {
return $this->belongsToMany(Subfleet::class, 'subfleet_fare')
->withPivot('price', 'cost', 'capacity');
}
*/
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Repositories;
use App\Models\Award;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Repository\Contracts\CacheableInterface;
class AwardRepository extends BaseRepository implements CacheableInterface
{
use CacheableRepository;
protected $fieldSearchable = [
'title' => 'like',
];
public function model()
{
return Award::class;
}
public function findByTitle($title) {
return $this->findByField('title', $title)->first();
}
}

View File

@ -14,6 +14,8 @@ Route::group([
Route::resource('fares', 'FareController'); Route::resource('fares', 'FareController');
Route::resource('awards', 'AwardController');
# subfleet # subfleet
Route::resource('subfleets', 'SubfleetController'); Route::resource('subfleets', 'SubfleetController');
Route::match(['get', 'post', 'put', 'delete'], 'subfleets/{id}/fares', 'SubfleetController@fares'); Route::match(['get', 'post', 'put', 'delete'], 'subfleets/{id}/fares', 'SubfleetController@fares');

View File

@ -0,0 +1,11 @@
@extends('admin.app')
@section('title', 'Add Award')
@section('content')
<div class="card border-blue-bottom">
<div class="content">
{!! Form::open(['route' => 'admin.awards.store']) !!}
@include('admin.awards.fields')
{!! Form::close() !!}
</div>
</div>
@endsection

View File

@ -0,0 +1,11 @@
@extends('admin.app')
@section('title', "Edit \"$award->title\" Award")
@section('content')
<div class="card border-blue-bottom">
<div class="content">
{!! Form::model($award, ['route' => ['admin.awards.update', $award->id], 'method' => 'patch']) !!}
@include('admin.awards.fields')
{!! Form::close() !!}
</div>
</div>
@endsection

View File

@ -0,0 +1,46 @@
<div class="row">
<div class="col-md-12">
<div class="callout callout-success">
Awards that can be granted to pilots.
</div>
<br />
</div>
</div>
<div class="row">
<div class="form-group col-sm-6">
{!! Form::label('title', 'Title:') !!}&nbsp;<span class="required">*</span>
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This will be the title of the award
</div>
{!! Form::text('title', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('image', 'Image:') !!}
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This is the image of the award. Be creative!
</div>
{!! Form::text('image', null, ['class' => 'form-control', 'placeholder' => 'Enter the url of the image location']) !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('description', 'Description:') !!}&nbsp
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This is the description of the award.
</div>
{!! Form::textarea('description', null, ['class' => 'form-control']) !!}
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
<div class="pull-right">
{!! Form::button('Save', ['type' => 'submit', 'class' => 'btn btn-success']) !!}
<a href="{!! route('admin.awards.index') !!}" class="btn btn-warn">Cancel</a>
</div>
</div>
</div>

View File

@ -0,0 +1,18 @@
@extends('admin.app')
@section('title', 'Awards')
@section('actions')
<li>
<a href="{!! route('admin.awards.create') !!}">
<i class="ti-plus"></i>
Add New
</a>
</li>
@endsection
@section('content')
<div class="card">
@include('admin.awards.table')
</div>
@endsection

View File

@ -0,0 +1,9 @@
@extends('admin.app')
@section('content')
<div class="card border-blue-bottom">
<div class="content">
@include('admin.awards.show_fields')
</div>
</div>
@endsection

View File

@ -0,0 +1,17 @@
<!-- Title Field -->
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
<p>{!! $award->title !!}</p>
</div>
<!-- Description Field -->
<div class="form-group">
{!! Form::label('Description', 'Description:') !!}
<p>{!! $award->description !!}</p>
</div>
<!-- Image Field -->
<div class="form-group">
{!! Form::label('image', 'Image:') !!}
<p><img src="{!! $award->image !!}" alt="No Image Available" /></p>
</div>

View File

@ -0,0 +1,23 @@
<table class="table table-hover table-responsive" id="awards-table">
<thead>
<th>Title</th>
<th class="text-center">Description</th>
<th class="text-center">Image</th>
<th class="text-right">Action</th>
</thead>
<tbody>
@foreach($awards as $award)
<tr>
<td>{!! $award->title !!}</td>
<td class="text-center">{!! $award->description !!}</td>
<td class="text-center"><img src="{!! $award->image !!}" name="{!! $award->title !!}" alt="No Image Available" /></td>
<td class="text-right">
{!! Form::open(['route' => ['admin.awards.destroy', $award->id], 'method' => 'delete']) !!}
<a href="{!! route('admin.awards.edit', [$award->id]) !!}" class='btn btn-sm btn-success btn-icon'><i class="fa fa-pencil-square-o"></i></a>
{!! Form::button('<i class="fa fa-times"></i>', ['type' => 'submit', 'class' => 'btn btn-sm btn-danger btn-icon', 'onclick' => "return confirm('Are you sure you want to delete this award?')"]) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>

View File

@ -35,6 +35,7 @@
class="pe-7s-map-marker"></i>airports</a></li> class="pe-7s-map-marker"></i>airports</a></li>
<li><a href="{!! url('/admin/users') !!}"><i class="pe-7s-users"></i>users</a></li> <li><a href="{!! url('/admin/users') !!}"><i class="pe-7s-users"></i>users</a></li>
<li><a href="{!! url('/admin/ranks') !!}"><i class="pe-7s-id"></i>ranks</a></li> <li><a href="{!! url('/admin/ranks') !!}"><i class="pe-7s-id"></i>ranks</a></li>
<li><a href="{!! url('/admin/awards') !!}"><i class="pe-7s-diamond"></i>awards</a></li>
<li><a href="{!! url('/admin/settings') !!}"><i class="pe-7s-id"></i>settings</a></li> <li><a href="{!! url('/admin/settings') !!}"><i class="pe-7s-id"></i>settings</a></li>
</ul> </ul>
</div> </div>