Skip to content

Commit

Permalink
add airports table and #7 integrate permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Jun 11, 2017
1 parent 35f660d commit d3cf57a
Show file tree
Hide file tree
Showing 25 changed files with 640 additions and 60 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ DB_USERNAME=
DB_PASSWORD=

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,38 @@ all: build

build:
composer install --no-interaction
php artisan optimize
php artisan config:cache
@make db

install:
install: db
echo ""

reset:
@rm database/testing.sqlite
@php artisan optimize
@php artisan config:clear
@sqlite3 database/testing.sqlite ""
@php artisan migrate:refresh --seed

db:
sqlite3 database/testing.sqlite ""
php artisan migrate
php artisan db:seed

unittest-db:
rm -f database/unittest.sqlite
sqlite3 database/unittest.sqlite ""
php artisan migrate:refresh --seed --env unittest

reset-db:
rm database/testing.sqlite
make db

tests: test

test:
vendor/bin/phpunit --testdox tests

schema:
#php artisan infyom:scaffold Airlines --fieldsFile=database/schema/airlines.json
php artisan infyom:scaffold Aircraft --fieldsFile=database/schema/aircraft.json
#php artisan infyom:scaffold Aircraft --fieldsFile=database/schema/aircraft.json
echo ""

docker:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ run the following commands. for right now, we're running on sqlite. for mysql, s
```bash
cp .env.example .env
composer install --no-interaction
php artisan optimize
sqlite3 database/testing.sqlite ""
php artisan migrate:refresh --seed
```
Expand Down
156 changes: 156 additions & 0 deletions app/Http/Controllers/Admin/AirportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Requests\CreateAirportRequest;
use App\Http\Requests\UpdateAirportRequest;
use App\Repositories\AirportRepository;
use App\Http\Controllers\AppBaseController as InfyOmBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class AirportController extends InfyOmBaseController
{
/** @var AirportRepository */
private $airportRepository;

public function __construct(AirportRepository $airportRepo)
{
$this->airportRepository = $airportRepo;
}

/**
* Display a listing of the Airport.
*
* @param Request $request
* @return Response
*/
public function index(Request $request)
{
$this->airportRepository->pushCriteria(new RequestCriteria($request));
$airports = $this->airportRepository->all();

return view('admin.airports.index')
->with('airports', $airports);
}

/**
* Show the form for creating a new Airport.
*
* @return Response
*/
public function create()
{
return view('admin.airports.create');
}

/**
* Store a newly created Airport in storage.
*
* @param CreateAirportRequest $request
*
* @return Response
*/
public function store(CreateAirportRequest $request)
{
$input = $request->all();

$airport = $this->airportRepository->create($input);

Flash::success('Airport saved successfully.');

return redirect(route('admin.airports.index'));
}

/**
* Display the specified Airport.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
$airport = $this->airportRepository->findWithoutFail($id);

if (empty($airport)) {
Flash::error('Airport not found');

return redirect(route('admin.airports.index'));
}

return view('admin.airports.show')->with('airport', $airport);
}

/**
* Show the form for editing the specified Airport.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
$airport = $this->airportRepository->findWithoutFail($id);

if (empty($airport)) {
Flash::error('Airport not found');

return redirect(route('admin.airports.index'));
}

return view('admin.airports.edit')->with('airport', $airport);
}

/**
* Update the specified Airport in storage.
*
* @param int $id
* @param UpdateAirportRequest $request
*
* @return Response
*/
public function update($id, UpdateAirportRequest $request)
{
$airport = $this->airportRepository->findWithoutFail($id);

if (empty($airport)) {
Flash::error('Airport not found');

return redirect(route('admin.airports.index'));
}

$airport = $this->airportRepository->update($request->all(), $id);

Flash::success('Airport updated successfully.');

return redirect(route('admin.airports.index'));
}

/**
* Remove the specified Airport from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
{
$airport = $this->airportRepository->findWithoutFail($id);

if (empty($airport)) {
Flash::error('Airport not found');

return redirect(route('admin.airports.index'));
}

$this->airportRepository->delete($id);

Flash::success('Airport deleted successfully.');

return redirect(route('admin.airports.index'));
}
}
11 changes: 8 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Models\Role;
use App\Models\User;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;

Expand Down Expand Up @@ -50,7 +51,7 @@ protected function validator(array $data)
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
'password' => 'required|min:5|confirmed',
]);
}

Expand All @@ -62,10 +63,14 @@ protected function validator(array $data)
*/
protected function create(array $data)
{
return User::create([
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);

$role = Role::where('name', 'admin')->first();
$user->attachRole($role);
return $user->refresh();
}
}
4 changes: 3 additions & 1 deletion app/Http/Controllers/Frontend/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Http\Controllers\Frontend;

class BaseController extends Controller
use App\Http\Controllers\AppBaseController;

class BaseController extends AppBaseController
{

}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Frontend/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class DashboardController extends BaseController
*/
public function index()
{
return view('frontend/dashboard');
return view('frontend.dashboard');
}
}
30 changes: 30 additions & 0 deletions app/Http/Requests/CreateAirportRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use App\Models\Airport;

class CreateAirportRequest extends Request
{

/**
* 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 Airport::$rules;
}
}
30 changes: 30 additions & 0 deletions app/Http/Requests/UpdateAirportRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use App\Models\Airport;

class UpdateAirportRequest extends Request
{

/**
* 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 Airport::$rules;
}
}
52 changes: 52 additions & 0 deletions app/Models/Airport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* Class Airport
* @package App\Models
*/
class Airport extends Model
{
use SoftDeletes;

public $table = 'airports';


protected $dates = ['deleted_at'];


public $fillable = [
'icao'
];

/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [

];

/**
* Validation rules
*
* @var array
*/
public static $rules = [
'icao' => 'required'
];

public function save(array $options = [])
{
if(in_array('icao', $options)) {
$options['icao'] = strtoupper($options['icao']);
}

return parent::save($options);
}
}
Loading

0 comments on commit d3cf57a

Please sign in to comment.