diff --git a/app/Http/Controllers/BulletinsController.php b/app/Http/Controllers/BulletinsController.php new file mode 100644 index 0000000..ae2c5cf --- /dev/null +++ b/app/Http/Controllers/BulletinsController.php @@ -0,0 +1,38 @@ + Bulletin::orderByDesc('created_at')->paginate(5), + ]); + } + + public function create() + { + return view('bulletins.create'); + } + + public function store(BulletinRequest $request) + { + $bulletin = new Bulletin($request->all()); + $bulletin->save(); + flashAlert(type: 'success', title: null, message: 'NOTAM created!', toast: true, timer: true); + + return redirect()->route('notams.index'); + } + + public function destroy(Bulletin $bulletin) + { + $bulletin->delete(); + flashAlert(type: 'info', title: null, message: 'NOTAM deleted.', toast: true, timer: true); + + return redirect()->route('notams.index'); + } +} diff --git a/app/Http/Controllers/ViewsController.php b/app/Http/Controllers/ViewsController.php index dd99bc9..ccf63bf 100644 --- a/app/Http/Controllers/ViewsController.php +++ b/app/Http/Controllers/ViewsController.php @@ -2,15 +2,15 @@ namespace App\Http\Controllers; +use App\Models\Bulletin; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Http; class ViewsController extends Controller { public function welcome() { $notams = Cache::remember('notams', now()->addMinutes(10), function () { - return json_decode(Http::timeout(5)->get('https://gist.githubusercontent.com/liessdow/78c35cbdeeb97add6a721d3d6b6f0078/raw')); + return Bulletin::orderByDesc('created_at')->take(3)->get(); }); return view('welcome', [ diff --git a/app/Http/Requests/BulletinRequest.php b/app/Http/Requests/BulletinRequest.php new file mode 100644 index 0000000..f611732 --- /dev/null +++ b/app/Http/Requests/BulletinRequest.php @@ -0,0 +1,20 @@ + ['required'], + 'subtitle' => ['nullable'], + 'content' => ['required'], + 'action_url' => ['nullable', 'url'], + 'alert_controllers' => ['nullable'], + 'alert_pilots' => ['nullable'], + ]; + } +} diff --git a/app/Models/Bulletin.php b/app/Models/Bulletin.php new file mode 100644 index 0000000..58ddcf4 --- /dev/null +++ b/app/Models/Bulletin.php @@ -0,0 +1,54 @@ +can('administrate'); + } + + public function update(VatsimAccount $user, Bulletin $bulletin): bool + { + return $user->can('administrate'); + } + + public function delete(VatsimAccount $user, Bulletin $bulletin): bool + { + return $user->can('administrate'); + } + + public function restore(VatsimAccount $user, Bulletin $bulletin): bool + { + return $user->can('administrate'); + } + + public function forceDelete(VatsimAccount $user, Bulletin $bulletin): bool + { + return $user->can('administrate'); + } +} diff --git a/database/factories/BulletinFactory.php b/database/factories/BulletinFactory.php new file mode 100644 index 0000000..c0ec675 --- /dev/null +++ b/database/factories/BulletinFactory.php @@ -0,0 +1,23 @@ + $this->faker->sentence(), + 'subtitle' => $this->faker->sentence(), + 'content' => $this->faker->realText(), + 'action_url' => $this->faker->url(), + 'alert_controllers' => $this->faker->boolean(), + 'alert_pilots' => $this->faker->boolean(), + ]; + } +} diff --git a/database/migrations/2023_04_24_170043_create_bulletins_table.php b/database/migrations/2023_04_24_170043_create_bulletins_table.php new file mode 100644 index 0000000..743f854 --- /dev/null +++ b/database/migrations/2023_04_24_170043_create_bulletins_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('title'); + $table->string('subtitle')->nullable(); + $table->text('content'); + $table->string('action_url')->nullable(); + $table->boolean('alert_controllers')->default(false); + $table->boolean('alert_pilots')->default(false); + $table->softDeletes(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('bulletins'); + } +}; diff --git a/database/seeders/BulletinsSeeder.php b/database/seeders/BulletinsSeeder.php new file mode 100644 index 0000000..66d450d --- /dev/null +++ b/database/seeders/BulletinsSeeder.php @@ -0,0 +1,14 @@ +count(10)->create(); + } +} diff --git a/resources/views/_layouts/main.blade.php b/resources/views/_layouts/main.blade.php index 2232603..bdb7faa 100644 --- a/resources/views/_layouts/main.blade.php +++ b/resources/views/_layouts/main.blade.php @@ -96,6 +96,9 @@
Some input was incorrect.
++ {{ $bulletin->subtitle }} +
+ @endif +{{ $bulletin->content }}
+