emargareten / inertia-modal

Implement backend-driven modal dialogs for Laravel+Inertia apps.
MIT License
62 stars 8 forks source link

Modal works on Overview page but not on subpages with dynamic URL #38

Closed BergBenji closed 3 months ago

BergBenji commented 3 months ago

Short description: I have the following routes:

Route::get('/overview', [\App\Http\Controllers\OverviewController::class, 'overview'])->name('overview');  
Route::get('/userprofile/{ucode}', [\App\Http\Controllers\UserController::class, 'profile'])->name('user.profile');  
Route::group(['prefix' => '{customerid}'], function() {  
  Route::get('/dashboard', [\App\Http\Controllers\DashboardController::class, 'dashboard'])->name('dashboard');  
}); 

If i call the modal from the Overview everything works. But if i call the same Userprofile Modal from a Customerdashboard '/{customerid}/dashboard' i get the error Uncaught (in promise) Error: Ziggy error: 'customerid' parameter is required for route 'dashboard'.

The Laravel Method to render the Modal

public function profile($ucode, Request $request) : Modal
    {
        $user = User::where('ucode', $ucode)->first();
        return Inertia::modal('Modals/Profile', [
            'userprofile' => $user
        ])
            ->baseRoute('overview');
    }

Any idea how to fix this? Dont have any ideas anymore.

BergBenji commented 3 months ago

Ok, i found the reason after rebuild some things. In the share method of "HandlerInertiaRequest" i had $returnarray['customerid'] = fn() => $request->route('customerid');

And if i call the user profile the customerid is not given but the share method will replace the prop with null.