Merge #154 Awards into dev
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
143
app/Http/Controllers/Admin/AwardController.php
Executable file
143
app/Http/Controllers/Admin/AwardController.php
Executable 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'));
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/CreateAwardRequest.php
Executable file
30
app/Http/Requests/CreateAwardRequest.php
Executable 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;
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/UpdateAwardRequest.php
Executable file
30
app/Http/Requests/UpdateAwardRequest.php
Executable 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
18
app/Http/Resources/Award.php
Executable 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
38
app/Models/Award.php
Executable 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');
|
||||
}
|
||||
*/
|
||||
}
|
||||
25
app/Repositories/AwardRepository.php
Executable file
25
app/Repositories/AwardRepository.php
Executable 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();
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@ Route::group([
|
||||
Route::resource('airports', 'AirportController');
|
||||
Route::match(['get', 'post', 'put', 'delete'], 'airports/{id}/expenses', 'AirportController@expenses');
|
||||
|
||||
# Awards
|
||||
Route::resource('awards', 'AwardController');
|
||||
|
||||
# aircraft and fare associations
|
||||
Route::resource('aircraft', 'AircraftController');
|
||||
Route::match(['get', 'post', 'put', 'delete'], 'aircraft/{id}/expenses', 'AircraftController@expenses');
|
||||
|
||||
Reference in New Issue
Block a user