inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.08k stars 234 forks source link

Allow URL override by defining a URL resolver #503

Closed rojtjo closed 11 months ago

rojtjo commented 1 year ago

This pull request provides an alternative solution to @FrittenKeeZ's pull request ( #499) by allowing you to configure a callback that resolves the current URL. This way it can be easily configured to anyone's needs by overriding the urlResolver method in the HandlesInertiaRequests middleware. When this method returns null it falls back to the default behavior.

Example:

use Inertia\Middleware;

class HandleInertiaRequests extends Middleware
{
    public function urlResolver(Request $request): ?callable
    {
        return fn (Request $request) => 'https://inertiajs.com/'.$request->getRequestUri();
    }
}
mahbubahmed commented 1 year ago

@rojtjo This is an elegant solution to fix broken URLs when the application is inside a sub-directory.

When can we expect to get this solution merged?

brgmn commented 1 year ago

Would really like to see this merged! Thanks @rojtjo for your great work! I think this could also solve running Laravel Nova 4.x in a subdirectory (based on inertia, broken at the moment).

PrasadChinwal commented 1 year ago

Thanks a lot for this PR @rojtjo 👍

Hey @reinink is this something you could see getting merged? There are numerous issues which could be resolved with this. Ex. #422 and #437

ngekoding commented 10 months ago

Any update for this?

Will the PR merged or any other solutions?