diff options
author | Mateja <mail@matejamaric.com> | 2020-11-02 15:25:36 +0100 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2020-11-02 15:25:36 +0100 |
commit | b5afd40a49a2c2b061865a501103ea2a060f4997 (patch) | |
tree | 64b8ced33431c908442881ff3e63b898023f3c3e | |
parent | cd8cfe9d6a0b786e03142ae492b2d0d52f92e4f8 (diff) | |
download | yota-laravel-b5afd40a49a2c2b061865a501103ea2a060f4997.tar.gz yota-laravel-b5afd40a49a2c2b061865a501103ea2a060f4997.zip |
Standardized controllers to CRUD...
-rw-r--r-- | app/Http/Controllers/NewsController.php | 92 | ||||
-rw-r--r-- | app/Http/Controllers/PagesController.php | 26 | ||||
-rw-r--r-- | app/Http/Controllers/ReservationsController.php | 21 | ||||
-rw-r--r-- | app/Http/Controllers/SpecialCallsController.php | 6 | ||||
-rw-r--r-- | routes/web.php | 38 |
5 files changed, 131 insertions, 52 deletions
diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php new file mode 100644 index 0000000..d44ebd9 --- /dev/null +++ b/app/Http/Controllers/NewsController.php @@ -0,0 +1,92 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; +use function dd; + +use App\Models\Post; + +class NewsController extends Controller +{ + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + $news = Post::orderBy('created_at', 'desc')->get(); + + //$data = ['news' => $news]; + //return view('pages.news')->with($data); + //return view('pages.news')->with('news', $news); + return view('pages.news', compact('news')); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function show($id) + { + // + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + // + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + // + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + // + } +} diff --git a/app/Http/Controllers/PagesController.php b/app/Http/Controllers/PagesController.php index ac7abab..5ca01c7 100644 --- a/app/Http/Controllers/PagesController.php +++ b/app/Http/Controllers/PagesController.php @@ -5,9 +5,6 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use function dd; -use App\Models\Post; -use App\Models\Reservation; - class PagesController extends Controller { public function index(Request $request) @@ -15,16 +12,6 @@ class PagesController extends Controller return view('pages.index'); } - public function news(Request $request) - { - $news = Post::orderBy('created_at', 'desc')->get(); - - //$data = ['news' => $news]; - //return view('pages.news')->with($data); - //return view('pages.news')->with('news', $news); - return view('pages.news', compact('news')); - } - public function gallery(Request $request) { return view('pages.gallery'); @@ -34,17 +21,4 @@ class PagesController extends Controller { return view('pages.sponsoring'); } - - public function activities(Request $request) - { - $activities = Reservation::where('approved', '1')->get(); - //$activities = Reservation::addSelect([ - //'specialCall' => SpecialCall::select('sign') - ////->whereColumn('reservations.specialCall', 'special_calls.id') - //->whereColumn('specialCall', 'id') - //->limit(1) - //])->get(); - - return view('pages.activities', compact('activities')); - } } diff --git a/app/Http/Controllers/ReservationsController.php b/app/Http/Controllers/ReservationsController.php index 4816993..d3b141e 100644 --- a/app/Http/Controllers/ReservationsController.php +++ b/app/Http/Controllers/ReservationsController.php @@ -14,13 +14,26 @@ use App\Models\SpecialCall; class ReservationsController extends Controller { - public function reserve(Request $request) + public function index(Request $request) + { + $activities = Reservation::where('approved', '1')->get(); + //$activities = Reservation::addSelect([ + //'specialCall' => SpecialCall::select('sign') + ////->whereColumn('reservations.specialCall', 'special_calls.id') + //->whereColumn('specialCall', 'id') + //->limit(1) + //])->get(); + + return view('pages.activities', compact('activities')); + } + + public function create(Request $request) { $signs = SpecialCall::all(); return view('pages.reserve', compact('signs')); } - public function reserveForm(Request $request) + public function store(Request $request) { //$validatedData = $request->validate([ //... @@ -72,13 +85,13 @@ class ReservationsController extends Controller } // Administration - public function reservations(Request $request) + public function edit(Request $request) { $data = Reservation::all(); return view('pages.reservations', compact('data')); } - public function reservationsForm(Request $request) + public function update(Request $request) { return Redirect::back(); } diff --git a/app/Http/Controllers/SpecialCallsController.php b/app/Http/Controllers/SpecialCallsController.php index 2ddf743..ed29346 100644 --- a/app/Http/Controllers/SpecialCallsController.php +++ b/app/Http/Controllers/SpecialCallsController.php @@ -13,13 +13,13 @@ use App\Models\SpecialCall; class SpecialCallsController extends Controller { - public function add(Request $request) + public function create(Request $request) { $data = SpecialCall::all(); return view('pages.callsigns', compact('data')); } - public function addForm(Request $request) + public function store(Request $request) { $rules = [ 'sign' => 'required' ]; $messages = [ 'sign.required' => 'You need to provide a callsign!' ]; @@ -45,7 +45,7 @@ class SpecialCallsController extends Controller return view('pages.editsign', compact('data')); } - public function editForm(Request $request, int $id) + public function update(Request $request, int $id) { if ($request->input('submit') == 'Edit callsign') { $rules = [ 'sign' => 'required' ]; diff --git a/routes/web.php b/routes/web.php index 84e1b7e..4e6b85c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\LoginController; +use App\Http\Controllers\NewsController; use App\Http\Controllers\PagesController; use App\Http\Controllers\ReservationsController; use App\Http\Controllers\SpecialCallsController; @@ -18,33 +19,32 @@ use App\Http\Controllers\SpecialCallsController; */ Route::get('/', [PagesController::class, 'index'])->name('home'); -Route::get('/news', [PagesController::class, 'news'])->name('news'); -Route::get('/gallery', [PagesController::class, 'gallery'])->name('gallery'); Route::get('/sponsoring', [PagesController::class, 'sponsoring'])->name('sponsoring'); -Route::get('/special-calls', [PagesController::class, 'activities'])->name('activities'); -Route::get('/special-calls/reserve', [ReservationsController::class, 'reserve'])->name('reserve'); -Route::post('/special-calls/reserve', [ReservationsController::class, 'reserveForm'])->name('reserveForm'); + +Route::get('/news', [NewsController::class, 'index'])->name('news'); +Route::get('/news/add', [NewsController::class, 'create'])->name('newsAdd')->middleware(['auth']); +Route::post('/news/add', [NewsController::class, 'store'])->name('newsAddForm')->middleware(['auth']); +Route::get('/news/edit/{id}', [NewsController::class, 'edit'])->name('newsEdit')->middleware(['auth']); +Route::post('/news/edit/{id}', [NewsController::class, 'update'])->name('newsEditForm')->middleware(['auth']); +Route::get('/news/delete/{id}', [NewsController::class, 'delete'])->name('newsDelete')->middleware(['auth']); -Route::get('/special-calls/add', [SpecialCallsController::class, 'add'])->name('addSign') - ->middleware(['auth']); -Route::post('/special-calls/add', [SpecialCallsController::class, 'addForm'])->name('addSignForm') - ->middleware(['auth']); +Route::get('/gallery', [PagesController::class, 'gallery'])->name('gallery'); -Route::get('/special-calls/edit/{id}', [SpecialCallsController::class, 'edit'])->name('editSign') - ->middleware(['auth']); -Route::post('/special-calls/edit/{id}', [SpecialCallsController::class, 'editForm'])->name('editSignForm') - ->middleware(['auth']); -Route::get('/special-calls/delete/{id}', [SpecialCallsController::class, 'delete'])->name('deleteSign') - ->middleware(['auth']); +Route::get('/special-calls', [ReservationsController::class, 'index'])->name('activities'); +Route::get('/special-calls/reserve', [ReservationsController::class, 'create'])->name('reserve'); +Route::post('/special-calls/reserve', [ReservationsController::class, 'store'])->name('reserveForm'); +Route::get('/special-calls/reservations', [ReservationsController::class, 'edit'])->name('reservations')->middleware(['auth']); +Route::post('/special-calls/reservations', [ReservationsController::class, 'update'])->name('reservationsForm')->middleware(['auth']); -Route::get('/special-calls/reservations', [ReservationsController::class, 'reservations'])->name('reservations') - ->middleware(['auth']); -Route::post('/special-calls/reservations', [ReservationsController::class, 'reservationsForm'])->name('reservationsForm') - ->middleware(['auth']); +Route::get('/special-calls/add', [SpecialCallsController::class, 'create'])->name('addSign')->middleware(['auth']); +Route::post('/special-calls/add', [SpecialCallsController::class, 'store'])->name('addSignForm')->middleware(['auth']); +Route::get('/special-calls/edit/{id}', [SpecialCallsController::class, 'edit'])->name('editSign')->middleware(['auth']); +Route::post('/special-calls/edit/{id}', [SpecialCallsController::class, 'update'])->name('editSignForm')->middleware(['auth']); +Route::get('/special-calls/delete/{id}', [SpecialCallsController::class, 'delete'])->name('deleteSign')->middleware(['auth']); Route::get('/login', [LoginController::class, 'login'])->name('login'); |