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 cb2db5d0..c0a51307 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 @@ -104,6 +104,16 @@ class CreateSettingsTable extends Migration 'type' => 'int', 'description' => 'The time in minutes to check for a duplicate PIREP', ], + [ + 'id' => $this->formatSettingId('pireps.hide_cancelled_pireps'), + 'order' => $this->getNextOrderNumber('pireps'), + 'name' => 'Hide Cancelled PIREPs', + 'group' => 'pireps', + 'value' => true, + 'default' => true, + 'type' => 'boolean', + 'description' => 'Hide any cancelled PIREPs in the front-end', + ], [ 'id' => $this->formatSettingId('pilots.id_length'), 'order' => $this->getNextOrderNumber('pilots'), diff --git a/app/Http/Controllers/Frontend/PirepController.php b/app/Http/Controllers/Frontend/PirepController.php index 54f1762d..56c24068 100644 --- a/app/Http/Controllers/Frontend/PirepController.php +++ b/app/Http/Controllers/Frontend/PirepController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Frontend; use App\Facades\Utils; use App\Models\Enums\PirepSource; +use App\Models\Enums\PirepState; use App\Repositories\Criteria\WhereCriteria; use App\Services\GeoService; use App\Services\PIREPService; @@ -54,7 +55,12 @@ class PirepController extends Controller { $user = Auth::user(); - $where = ['user_id' => $user->id]; + $where = [['user_id', $user->id]]; + + if(setting('pireps.hide_cancelled_pireps')) { + $where[] = ['state', '<>', PirepState::CANCELLED]; + } + $this->pirepRepo->pushCriteria(new WhereCriteria($request, $where)); $pireps = $this->pirepRepo->orderBy('created_at', 'desc')->paginate();