model view controller - Laravel 5 stylesheets and scripts not loading for non-base routes -


i having trouble linking stylesheets, scripts, , images non-base route in laravel 5 app. when access example.com/about scripts , stylesheets working correctly if access example.com/about/something scripts , stylesheets link example.com/about/css/style.css rather example.com/css/style.css

my code follows:

routes.php:

 route::get('about/{slug?}', ['as' => 'officerprofile', 'uses' => 'pagescontroller@about']); 

pagescontroller.php:

public function about($slug = 'president') {     $officers = officer::all();     $currentofficer = officer::where('slug', $slug)->first();     return view("pages.about", ['title' => $this->maketitle('learn us')])->with('officers', $officers)->with('currentofficer', $currentofficer); } 

layout.blade.php:

{!! html::script('https://code.jquery.com/jquery-2.1.4.min.js') !!} {!! html::script('js/skel.min.js') !!} {!! html::script('js/skel-layers.min.js') !!} {!! html::script('js/init.js') !!} {!! html::script('js/scripts.js') !!} <noscript>     {!! html::style('css/skel.css') !!}     {!! html::style('css/style.css') !!}     {!! html::style('css/style-desktop.css') !!} </noscript> 

for reason laravel thinking base url example.com/about when loaded route example.com/about/something. have tried still routes example.com/about/images/image.jpg rather example.com/images/image.jpg. advice appreciated. thank you!

you using relative paths , need absolute paths. see example below, thing added prepended /

{!! html::script('https://code.jquery.com/jquery-2.1.4.min.js') !!} {!! html::script('/js/skel.min.js') !!} {!! html::script('/js/skel-layers.min.js') !!} {!! html::script('/js/init.js') !!} {!! html::script('/js/scripts.js') !!} <noscript>     {!! html::style('/css/skel.css') !!}     {!! html::style('/css/style.css') !!}     {!! html::style('/css/style-desktop.css') !!} </noscript> 

a relative path loads files related current path. eg page http://example.com/about/us can relatively load images/logo.png results in actual request http://example.com/about/images/logo.png.

an absolute path hostname: same example above you'd load /images/logo.png results in http://example.com/images/logo.png


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -