Skip to content

Instantly share code, notes, and snippets.

@khanalpride
Forked from tanthammar/HasLinks.php
Created June 22, 2020 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khanalpride/fee06c1de3df703a32ead503a3e9dbf0 to your computer and use it in GitHub Desktop.
Save khanalpride/fee06c1de3df703a32ead503a3e9dbf0 to your computer and use it in GitHub Desktop.
No more controllers! Only Laravel LiveWire SPA routes and a handy Eloquent Model trait.
<?php
Route::group([
'prefix' => 'app',
'as' => 'app.',
//'namespace' => 'App', //not needed with livewire
'middleware' => ['auth'],
], function () {
Route::livewire('/', 'app.dashboard')->name('dashboard');
$resources = [
'post',
'user',
'team',
'booking',
//continue with all your models.
];
foreach ($resources as $resource) {
Route::livewire("/{$resource}s", "app.{$resource}s.index")->name("{$resource}s.index");
Route::livewire("/{$resource}s/{{$resource}}", "app.{$resource}s.show")->name("{$resource}s.show");
if($resource != 'booking') {//non-default
Route::livewire("/create/{$resource}", "app.{$resource}s.create")->name("{$resource}s.create");
}
Route::livewire("/{$resource}s/edit/{{$resource}}", "app.{$resource}s.edit")->name("{$resource}s.edit");
Route::livewire("/{$resource}s/delete/{{$resource}}", "app.{$resource}s.delete")->name("{$resource}s.delete");
}
//non-default
Route::livewire('/create/booking/{event?}', "app.bookings.create")->name("bookings.create"); //event is optional
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment