Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tha07's avatar
Level 2

Hosting Laravel API with Angular Front end

Hi all, I searched everywhere about hosting both apps and there are several recommendations.

  1. Hosting both as different apps.

  2. Including Angular dist folder items in Laravel public folder with some settings.

What is the easiest and the best way to host both apps, without interfering the routes?

0 likes
15 replies
topvillas's avatar

What sort of things are you talking about?

A complete Angular SPA with a Laravel backend API?

1 like
fylzero's avatar

@tha07 Really up to you. If it is one app, might as well be one codebase. Laravel is kind of structured for that. You can organize your routes so "interference" isn't really a thing.

2 likes
fylzero's avatar

Also... please try out Vue. It is sooooo much easier to write. ;)

2 likes
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

I have a complete react spa that is running on laravel

My web.php has this single route which just serve a single index.blade.php file

Route::view('/{path?}', 'index')
    ->where('path', '.*')
    ->name('react');

And then I have made a separate ajax.php route file for all my react routes, setup kinda like an API, except it uses the web middleware group, to allow sessions, auth etc.

protected function mapAjaxRoutes()
    {
        Route::prefix('ajax')
            ->middleware('web')
            ->namespace($this->namespace . '\Ajax')
            ->group(base_path('routes/ajax.php'));
    }

For never projects I use inertiajs to make this whole think much much easier though :)

2 likes
fylzero's avatar

@sinnbeck I made the exact same thing (ajax Route Service block) in one of my apps but did not think of using namespace there!!! That is brilliant! I'm going to use that. Thank you.

3 likes
tha07's avatar
Level 2

@sinnbeck how to tell Laravel to load the index.html file which is bootstrapping my angular app. I mean js files are not enough to run the angular app. routes, index.html file. how are they need to be reconfigured?

Sinnbeck's avatar

Swap the index.html for index.blade.php

It is essentially the same.

Just put all the stuff right into there :) If you need more files you can use web.php to serve those "html" files :)

1 like
tha07's avatar
Level 2

@sinnbeck, Now I got it. thanks for the clarification. I'll try this with Angular. :)

Sinnbeck's avatar

Sounds good. If you end up using any of these suggestions, you can consider making a best answer :)

1 like

Please or to participate in this conversation.