I lose my bootstrap styles when passing variable (get) to route->Controller->View in Laravel 4

I am integrating a Bootstrap template to laravel 4 and I am having an issue when passing variables through the GET method. My final View renders without any style applied.

Let’s say I have a link like this:

<a href="{{url('offer')}}" rel="nofollow noreferrer noopener">Oferta 2015</a>

caught by a route like this>
Route::get('offer','<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d098bfbdb593bfbea4a2bfbcbcb5a290a3b8bfa79fb6b6b5a2">[email protected]</a>');

And the controller like:
public function showOffer()
{
    $Cursos = Curso::paginate(10);
    return View::make('cursos.offer')->with('cursos',$Cursos);
}

That works just fine (the master view extended by the offer view renders perfectly).

My issue happens when I try to pass a variable like this>

link:<a href="{{url('offer/2015')}}" rel="nofollow noreferrer noopener">Oferta 2015</a>

route: Route::get('offer/2015',array('myYear'=>'year','uses'=>'[email protected]'));

What happens here is that I get the View displayed, but with no styles at all. Just like when you get rid of the “link href …” in the header.

Any idea would be highly appreciated, thanks.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Currently you have defined all your include paths relative. So when the directory level in the URL changes the styles don’t get found. You should use the helpers Laravel provides to generate a full URL.

There’s asset()

<link href="{{ asset('assets/css/bootstrap.min.css') }}" rel="nofollow noreferrer noopener" rel="stylesheet">

Or even a helper to create the full link tag for including
{{ HTML::style('assets/css/bootstrap.min.css') }}

(And there’s one for javascript files too)
{{ HTML::script('assets/js/script.js') }}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x