Linking asset files to views in Laravel4

laravel, laravel-4

Solution

If your asset folder is inside public folder of laravel then user this:

Suppose your folder structure is public/assets/css/bootstrap: Then

 <script src="{{ URL::asset('assets/css/bootstrap.css') }}"></script>

Problem

Hi I am newbie learning laravel 4 for creating an application. I am trying to link twitter bootstrap3 files to views using laravel blades. I installed a new laravel application folder. To remove public from url path i removed all the file in public folder and kept outside of public folder. I changed paths as per the above changes in index.php file.As per my needs i will have two sections in my application one is for users and another is for admin. So for this i changed my routes.php file like this below. ``` Route::get('/', 'HomeController@index'); Route::get('/admin', 'AdminController@index'); ``` I created two controllers one for users and another for admin named as HomeController and AdminController. Both files will look like below. ``` HomeController for Users <?php class HomeController extends BaseController { public function index() { return View::make('index'); } } AdminController for admin section <?php class AdminController extends BaseController { public function index() { return View::make('admin.index'); } } ``` Now i created admin folder under views folder for admin section. Thats why i kept `admin.index` to call admin index page when the url is like this `http://localhost/laravel/admin`. Now i created assets folder which has css folder for css files, js folder js files and images folder for images. I want to link these css and js files to my admin view. So i created a `layout.blade.php` like below. ``` <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Laravel</title> <link rel="stylesheet" href="{{ asset('assets/css/bootstrap.css') }}"> <link rel="stylesheet" href="{{ asset('assets/css/style.css') }}"> <script type="text/javascript" src="{{ asset('assets/js/jquery-1.10.1.min.js') }}"></script> <script type="text/javascript" src="{{ asset('assets/js/bootstrap.min.js') }}"></script> </head> <body> @yield('content') </body> </html> ``` After this i changed my view into like this below. ``` @extends('layout') @section('content') <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <p>Here Comes Admin Section</p> </div> </div> </div> @stop ``` But the assets are not linking. May i know where i am going wrong.

Original source