From 8acb9291fe19590a8e614cca2152a8ba55cc5820 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 10 Feb 2018 13:25:40 -0600 Subject: [PATCH] hide all cancelled pireps #180 --- .../migrations/2017_06_07_014930_create_settings_table.php | 4 ++-- app/Http/Controllers/Frontend/PirepController.php | 5 +---- app/Models/User.php | 4 +++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Database/migrations/2017_06_07_014930_create_settings_table.php b/app/Database/migrations/2017_06_07_014930_create_settings_table.php index 4f1440ca..d3cfced5 100644 --- a/app/Database/migrations/2017_06_07_014930_create_settings_table.php +++ b/app/Database/migrations/2017_06_07_014930_create_settings_table.php @@ -136,13 +136,13 @@ class CreateSettingsTable extends Migration 'description' => 'The time in minutes to check for a duplicate PIREP', ]); - $this->addSetting('pireps.hide_cancelled_pireps', [ + /*$this->addSetting('pireps.hide_cancelled_pireps', [ 'name' => 'Hide Cancelled PIREPs', 'group' => 'pireps', 'value' => true, 'type' => 'boolean', 'description' => 'Hide any cancelled PIREPs in the front-end', - ]); + ]);*/ $this->addSetting('pireps.restrict_aircraft_to_rank', [ 'name' => 'Restrict Aircraft to Ranks', diff --git a/app/Http/Controllers/Frontend/PirepController.php b/app/Http/Controllers/Frontend/PirepController.php index 4a14700d..e05d7ce9 100644 --- a/app/Http/Controllers/Frontend/PirepController.php +++ b/app/Http/Controllers/Frontend/PirepController.php @@ -94,10 +94,7 @@ class PirepController extends Controller $user = Auth::user(); $where = [['user_id', $user->id]]; - - if(setting('pireps.hide_cancelled_pireps')) { - $where[] = ['state', '<>', PirepState::CANCELLED]; - } + $where[] = ['state', '<>', PirepState::CANCELLED]; $this->pirepRepo->pushCriteria(new WhereCriteria($request, $where)); $pireps = $this->pirepRepo->orderBy('created_at', 'desc')->paginate(); diff --git a/app/Models/User.php b/app/Models/User.php index afc667dd..fd0726ae 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Models\Enums\PirepState; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use Laratrust\Traits\LaratrustUserTrait; @@ -159,7 +160,8 @@ class User extends Authenticatable public function pireps() { - return $this->hasMany(Pirep::class, 'user_id'); + return $this->hasMany(Pirep::class, 'user_id') + ->where('state', '!=', PirepState::CANCELLED); } public function rank()