Routes were better?

Hey guys , 2.0 it’s great . I love all the new features , except removing the Route::livewire .

Just want to know what you guys think and how do you manage them in web.php .

If you had Customers create, users create , services create and many others how do you name the components ?

In v1 was customers.create , but in v2 I have to call them customers.customers-create or else in web.php it’s a mess with all routes with the Create::class .

Also I have an app with more than 100 Create components and it will be a pain to upgrade it.

Just curious what’s your approach and is there some way to keep Route::livewire in v2 ?

Thanks

Hey, @tiagosimoesdev
You can just change the livewire method to the regular laravel verbs and you are good, no need to refactor every route, especially if you have an alias name inside the route itself.

Hi @skywalker , Thanks for replying .

For example I have
Route::livewire('login', 'auth.login') ->name('login');

If I change to
Route::get('login', 'auth.login')->name('login');

it breaks… I need to change to
Route::get('login', Login::class) ->name('login');

This one is kind of okay because I only have 1 named Login::class , but i have a ton of Create::class after upgrading the web.php will be a mess with a ton of the same named Create::class

So , before :

Route::livewire('/users/create', 'users.create')->layout('layout.default')->middleware('perm:settings.users.create');

Route::livewire('/organizations/create', 'organizations.create')->layout('layout.default')->middleware('perm:others.organizations.create');

Route::livewire('/ingredients/create', 'ingredients.create')->layout('layout.default')->middleware('perm:others.ingredients.create');

After:

Route::get('/users/create', Create::class)->middleware('perm:settings.users.create');

Route::get('/organizations/create', Create::class)>middleware('perm:others.organizations.create');

Route::get('/ingredients/create', Create::class)->middleware('perm:others.ingredients.create');

What do you tink it’s the best approach here ?

I see, but you can put the full namespace and will be better like:

Rouute::get('/ingredients/create', App\Http\Controllers\YourController\Create::class)
             ->middleware('perm:others.ingredients.create');

Or if you want a major refactor you must rename your controllers such as UserCreateController or something like that, it will be better for developing your application and for more clean code.

Updates:
you can alias your component name when you call them like so:

use Path\To\Your\Component\Index;
use Path\To\Another\Component\Index as AnotherIndex;

Route::get('index', Index::class)->name('index');
Route::get('another-index', AnotherIndex::class)->name('another-index');

My favourite thing to do is import a partial namespace with a use statement so that there’s more context when you use the ::class syntax later on:

use App\Http\Livewire;

Route::get('/users/create', Livewire\Settings\Create::class);

Route::get('/organizations/create', Livewire\Organizations\Create::class);

Route::get('/ingredients/create', Livewire\Ingredients\Create::class);

Alternatively, import multiple namespaces at once, so using them inline is even simpler:

use App\Http\Livewire\{Settings, Organizations, Ingredients};

Route::get('/users/show', Settings\Show::class);
Route::get('/users/create', Settings\Create::class);

Route::get('/organizations/show', Organizations\Show::class);
Route::get('/organizations/create', Organizations\Create::class);

Route::get('/ingredients/show', Ingredients\Show::class);
Route::get('/ingredients/create', Ingredients\Create::class);
2 Likes