Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Developer654079525's avatar

Blade and paths

Everything renders fine when displaying a page through a the following route:

Route::get('/blog', function () {
    $post = // some logic
    return view('blog', [
    'posts' => $posts,
     ]);
})->name('blog'); // named route

But when I use another route for blog details, the page displays but is not properly rendered as it can't see the css and js files anymore:

Route::get('/blog/{id}/{slug}', function (string $id, string $slug) {
    $post = // some logic
    return view('blog', [
    'post' => $post,
    ]);
})->name('blog'); // named route

What needs to be modified to have the website/postid/slug path and properly render the templates?

0 likes
4 replies
tykus's avatar

Probably an issue of relative paths; how is the CSS and JS linked in the View (or Layout) template?

tykus's avatar
tykus
Best Answer
Level 104

@Developer654079525 yes, so as mentioned above, you are using relative paths to the assets, but whenever there is more that one URL segment, it will fail. Instead use absolute paths to the assets, so they are resolved from the base URL of your application (note the leading / - this assumes the assets are in subdirectories of the public directory:

<link rel="stylesheet" href="/css/style.css" />
<script src="/js/app.js"></script>
martinbean's avatar

@Developer654079525 Use absolute URLs, not relative ones. You can load assets like CSS and JavaScript using the asset helper method.

If you have a CSS file at public/css/app.css, then in your Blade layout template you’d add something like:

<link href="{{ asset('css/app.css') }}" rel="stylesheet">

Please or to participate in this conversation.