1

my localhost uses a laravel route to open my view, which works:

http://localhost/view/stock/equipment

Laravel 4 route which returns my view:

Route::get('view/stock/equipment', array('uses'=>'App\Controllers\Stock\EquipmentController@getIndex'));

my view contains:

        {{ HTML::script('js-views/stock/equipment/bootstrap.js') }}

Which shows in my html page as:

<script src="http://localhost/js-views/stock/equipment/bootstrap.js"></script>

But bootstrap.js won't load, when I look using firebug I see it doesn't get loaded from the correct path:

 GET http://localhost/view/stock/bootstrap.js   404 Not Found

I can see a ' view/stock part ' coming from the laravel route.

the public path is set correctly in Laravel.

How could this be?

1
  • I've noticed that the GET 404 not found is called from within bootstrap.js - so I should check bootstrap.js I guess. Commented Sep 19, 2014 at 1:20

2 Answers 2

1

So what happens if you go to http://localhost/js-views/stock/equipment/bootstrap.js in your browser? You should see the javascript file.

Why do you store your javascript together with your stock equipment? Wouldn't it be better to place it in a assets folder? This how I structure my assets (under laravel/public):

assets/
       css/
       img/
       js/

Define the paths in a assets.php config file:

return array(
    'css' => '/assets/css',
    'img' => '/assets/img',
    'js' => '/assets/js'
);

And then use a helper function to return their URLs:

class Asset
{
    private static function getUrl($type, $file)
    {
        return URL::to(Config::get('assets.' . $type) . '/' . $file);
    }

    public static function css($file)
    {
        return self::getUrl('css', $file);
    }

    public static function img($file)
    {
        return self::getUrl('img', $file);
    }

    public static function js($file)
    {
        return self::getUrl('js', $file);
    }

}

So to display an image I can do this:

HTML::image(Asset::img('logo/full.png'), "My website logo")

But I let MaxCDN host Bootstrap for me (code from Bootstrap website):

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer hebron. bootstrap.js is a extjs part for a extjs grid I want to display in my blade view. localhost/js-views/stock/equipment/bootstrap.js opens the bootstrap.js no problem here. I later found that bootstrap is loaded from the blade view.. I think some part(code) in the bootstrap.js is conflicting with the laravel route and then throws a 404 error... So this appears to be a different problem in the end.
That is why it is unwise to mix your assets with your routes. As I said I too use the Bootstrap framework, but I get it from MaxCDN with the links in my answer, I do not host it myself.
Thanks hebron, you really understood my problem. Solved. You should earn 1K for this.
Where to place asset.php file and assets class..please make it clear
0

save the javascript file to /var/www/yourprojectname/public folder/js

and use <script src="{{ asset('js/main.js') }}"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.