🔧 Development
K Kate Feb 27, 2024

Authentication w/ existing Laravel app

Hi,
installed Laravel and Waterhole fluently, but stuck on the last part.
Where exactly do I have to add this piece of code. Add the following to "a Service Provider". I know where Service Providers are but don't use them

Extend\ForumRoutes::add(function () {
    Route::name('login')->get(
        'login',
        fn() => redirect()
            ->setIntendedUrl(url()->previous())
            ->route('login'),
    );
});

When i add it to boot in the AppServiceProvider i get an error

Illuminate\Routing\Route::name() cannot be called statically

⁨6⁩ ⁨Comments⁩

Toby Toby Waterhole Founder Feb 28, 2024

Hi @Kate, you should add that code to the extend method of WaterholeServiceProvider – see this page on the docs for more information.

Also, the error looks like you might've imported Illuminate\Routing\Route instead of Illuminate\Support\Facades\Route?

I shall make some improvements to the docs to make these things clearer!

Toby Toby Waterhole Founder Mar 25, 2024
In reply to K Kate

Ah, I see - that link is a part of Waterhole by default so I wasn't sure if it was the one you were talking about. But, it only shows up if there is a route named waterhole.register - and if you have set the allow_registration config to false (as you should when setting up the Laravel integration), then that route won't exist.

The solution is to register your own register route to redirect to your app's registration page, similar to what should already be doing for the login route:

Extend\ForumRoutes::add(function () {
    Route::name('register')->get(
        'register',
        fn() => redirect()
            ->setIntendedUrl(url()->previous())
            ->route('register'),
    );
});
In reply to Toby Toby

Hey @Toby, for the Laravel Integration portion of the docs, maybe you could add a step to create a symbolic link from public/storage to storage/app/public by running the command below. Otherwise the js/css files won't load when visiting the waterhole portion of the application.

php artisan storage:link 

I wasn't sure where to post this as I can't submit changes to the docs.