Skip to content

Instantly share code, notes, and snippets.

@ramaID
Forked from tanthammar/HasLinks.php
Created October 14, 2020 14:32
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 ramaID/04cdc67564643d53ae5110f521a605f0 to your computer and use it in GitHub Desktop.
Save ramaID/04cdc67564643d53ae5110f521a605f0 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 = [
'user',
'person', //becomes people
'event',
'booking',
//continue with all your models.
];
foreach ($resources as $resource) {
$plural = \Str::plural($resource);
Route::livewire("/{$plural}", "app.{$plural}.index")->name("{$plural}.index");
Route::livewire("/{$plural}/{{$resource}}", "app.{$plural}.show")->name("{$plural}.show");
if($resource != 'booking') {//non-default
Route::livewire("/create/{$resource}", "app.{$plural}.create")->name("{$plural}.create");
}
Route::livewire("/{$plural}/edit/{{$resource}}", "app.{$plural}.edit")->name("{$plural}.edit");
Route::livewire("/{$plural}/delete/{{$resource}}", "app.{$plural}.delete")->name("{$plural}.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