mhmiton / laravel-modules-livewire

Using Laravel Livewire in Laravel Modules package with automatically registered livewire components for every modules.
MIT License
184 stars 35 forks source link

Invalid Route #3

Closed diorz38 closed 3 years ago

diorz38 commented 3 years ago

when i try to create Livewire Module, this us what happen:

UnexpectedValueException
Invalid route action: [Modules\Backend\Http\Controllers\Modules\Backend\Http\Livewire\Pengguna\IndexPage].`

step to reproduce: install laravel 8, package i use:

        "laravel/framework": "^8.12",
        "livewire/livewire": "^2.3",
        "mhmiton/laravel-modules-livewire": "dev-master",
        "nwidart/laravel-modules": "^8.0",

in terminal:

php artisan vendor:publish --provider="Mhmiton\LaravelModulesLivewire\LaravelModulesLivewireServiceProvider"
php artisan module:make Backend
php artisan module:make-livewire Backend Pengguna/IndexPage

in routes/web.php (inside modules Backend):

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
 */

Route::get('/pengguna', \Modules\Backend\Http\Livewire\Pengguna\IndexPage::class)->name('pengguna.index');

in my component:

<?php

namespace Modules\Backend\Http\Livewire\Pengguna;

use Livewire\Component;

class IndexPage extends Component
{
    public function render()
    {
        return view('backend::livewire.pengguna.index-page')
            ->extends(config('backend.extends.default'));
    }
}

my module Config:

<?php

return [
    'name' => 'Backend',
    'extends' => [
        'default' => 'backend::layouts.dafault'
    ]
];

when i change mabWebroute just like you suggest, to this:

    protected function mapWebRoutes()
    {
        Route::middleware('web')
            // ->namespace($this->moduleNamespace)
            ->group(module_path('Backend', '/Routes/web.php'));
    }

another error appear:

InvalidArgumentException
View [layouts.dafault] not found. (View:

but i make sure that layouts default.blade.php exist

mhmiton commented 3 years ago

Please try this solution - https://github.com/mhmiton/laravel-modules-livewire/issues/2#issuecomment-761831051

diorz38 commented 3 years ago

yes i have try that, but another error appear:

InvalidArgumentException
View [layouts.dafault] not found.

and my route module break also i aready try your example too, and it works, what the differents? even the route for normal module still break

mhmiton commented 3 years ago

Here is a spelling mistake. You need to correction in the backend module config file.

'default' => 'backend::layouts.dafault' to 'default' => 'backend::layouts.default'

diorz38 commented 3 years ago

After performed php artisan optimize:clear its all good now, except the module's route for a page without livewire still broke. hope u'll solve that soon.

thx

mhmiton commented 3 years ago

You removed the module route namespace, so you should use the laravel default route like this -

use Modules\Auth\Http\Controllers\Backend\LoginController as BackendLoginController;
use Illuminate\Support\Facades\Route;

Route::get('backend/login', [BackendLoginController::class, 'index'])->name('backend.login');

You can check this - https://laravel.com/docs/8.x/routing#the-default-route-files

Also, I will try to add a separate route macro to support the module route namespace in this package.