Home > Enterprise >  Laravel CSS not Instaling When Adding {id} in route
Laravel CSS not Instaling When Adding {id} in route

Time:07-28

CSS is working when i write route

Route::get('/showproduct', [ShowController::class,'index'])->name('showproduct');

Also Controller: ShowController

public function index()
    {
        //
        return view('home.showproduct');
    }

But in that way

Route

Route::get('/showproduct/{id}', [ShowController::class,'index'])->name('showproduct');

And Controller: ShowController

public function index($id)
    {
        //
        return view('home.showproduct',['id'=>$id]);
    }

Just html is comes, css and javascript not installing.

View folder name also showproduct.blade.php in home folder.

CodePudding user response:

It seems you include css and js is reference to relative/current directory like below:

<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>

You should add a leading slash (/) to the path like below:

<link rel="stylesheet" type="text/css" href="/style.css">
<script src="/script.js"></script>

or could be better use asset() to use a full URL

<link rel="stylesheet" type="text/css" href="{{asset('css/layouts/style-horizontal.css')}}">

<script src="{{asset('js/plugins.js')}}"></script>
  • Related