AngularJS Applications in Laravel

2.0.1 2019-02-17 08:26 UTC


This plugin provides a great eloquent way of creating HTML5 applications with AngularJS, Angular, ReactJS, Vue and many more.

Don't go with the name of the package i.e. laravel-angular-app, because initially, this package was designed to create only AngularJS applications, but now it's objective is to create, build and load assets in an elegant way in Laravel.


composer require shridharkaushik29/laravel-angular-app


Add the provider in config/app.php. Skip this step if you are using Laravel version greater than 5.4.

"providers" => [

Creating multiple apps per Laravel Installation.

This package offers to create multiple webpack applications in a single Laravel installation. For example, if you want to create an E-Commerce application, then it would require a separate application to manage the content for the front end application. This is handled very efficiently in this package because you can create as many applications you want with different blades.

Creating Blade View

{{--Used to set app name--}}
{{--Used to define site route name--}}
@title("Laravel React")
{{--Used to define application title--}}
{{--Used to define services route, when defined a $servicesUrl variable is defined in javascript--}}
<html lang="en">
    <base href="{{$app->url()}}/">
    <link href="{{asset("img/laravel-developer.png")}}" rel="shortcut icon"/>
    <link href="{{$app->asset("style.css")->url()}}" rel="stylesheet"/>
    {{--Used to print <script> tag containing javascript variables--}}
<div id="app"></div>
<div class="pre-loader" ng-if="showPreloader">
    <img class="logo" src="{{asset("storage/laravel-logo.png")}}">
    <p>Loading Application</p>
<script src="{{$app->asset("runtime.js")->url()}}" async></script>
<script src="{{$app->asset("vendor.js")->url()}}" async></script>
<script src="{{$app->asset("main.js")->url()}}" async></script>

Loading View

There's nothing special required to load views, it's as usual.

Route::get('/', function () {
    return view('welcome');

Creating Assets

This package assumes a folder with the app name in public/assets directory, where all of the assets are placed for that application.

For example, if an app is having name welcome, then there should be a directory public/assets/welcome containing all the javascript, css, images and other assets required by that application.

Loading Assets

$app->asset("path/for/asset") will return an instance for Shridhar\Bower\Asset class.

It contains an url() method which return an absolute url for that asset.

<link href="{{$app->asset("style.css")->url()}}" rel="stylesheet"/> 
<script src="{{$app->asset("runtime.js")->url()}}" async></script>
<img src="{{$app->asset("logo.jpg")->url()}}">