livewire laravel route problem!
larvel 8 remove Providers/RouteServiceProvider.php namespace. Maybe you add back again.
protected $namespace = 'App\Http\Controllers';
...
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
Add backup namespace then get problem for livewire. Every route just use App\Http|controllers ooxxooxxooxx.
OLD Way
web.php
Route::resource('users', 'UsersController');
Route::delete('users/destroy', 'UsersController@massDestroy');
Get Error
Route::resource('orders', 'livewire.order');
Route::resource('orders', 'livewire@order');
Route::view('orders', [\App\Http\Livewire\Order::class, 'render']);
Maybe Way
web.php
Route::view('orders', 'livewire.order');
Files:
\app\Http\Livewire\Order.php inside use return view('livewire.order');
\resources\views\livewire\order.blade.php
Get Error
Undefined variable: orders or other ooxxooxx
Alwasy get this Error.
````````` ```
web.php
Route::get('/admin/orders', [\App\Http\Livewire\Order::class, 'render']);
Files:
\app\Http\Livewire\Order.php
And use
return <<<'blade'
blade;
Get plain text @foreach($orders as o$key -> $permission
Same Error.
`````Beacuse view run first. Only create view then @livewire('')
example:
order and orderlist
order view for fist(main) load page. orderlist be loaded by order view. order view have @livewire('orderlist').
https://stackoverflow.com/questions/64038485/laravel-livewire-components-or-controllers
or just remove namespace
------------------------
Route::get('/admin/orders', \App\Http\Livewire\Order::class);
Don't add namespace in app/Http/livewire/ any file. Always get errors.
----------------------------------------------------------------------
` `` `````` ``````` ````````