3
votes

When I user this Route :

Route::get('home', function()
{
   return View::make('index');
});

with URL:

localhost/laravel/public/home

It get the view and works well .

But when use this Route:

Route::get('home/{id}', function($id)
{
    return View::make('index')->with('id', $id);
});

with URL:

localhost/laravel/public/home/10

It the view but doesn't work well that view come without any CSS, JS, .. etc

I can't define the ERROR here ?!

4
Is there a reason you not pointing the servers' document root to Laravel's public directory? - Bogdan
Can make it more clear please, I'm new with laravel !! - Mahmoud Nassar
The HTTP server you're using has a directive that allows you to set the directory that is visible for public requests. That is called the document root. I'll assume you're using either Apache or nginx (because they're the most common), and you can search for examples on how to configure the document root for any of them. It might also help if you can give more info regarding your enviroment Windows, Linux, OSX? And how are you managing your software stack? - Bogdan
Also try adding this line <base href="http://localhost/laravel/public/"> to the <head> section of your pages . Depending on how the path of your resources is defined this might fix the issue. However I still strongly suggest that you take the approach I suggested in my previous comments. - Bogdan
Ok it's work well now, after adding this line <base href="localhost/laravel/public"> to <head> Thansks :) - Mahmoud Nassar

4 Answers

17
votes

Yeah, I know this might be very late for this question, but I also got the same problem and stuck in the same situation. After reading and researching on google, I got the answer. I hope it may help someone.

This problems occurrs because we are using the relative path in our blade template and the solution is so simple, We have to use only the asset function to overcome this problem.

So change your code like this...

<link href="{{ asset('css/bootstrap.min.css') }}" rel='stylesheet' type='text/css' />
<script src="{{ asset('js/jquery.min.js') }}"> </script>

Hope that helps.

Happy Coding :)

1
votes

Controller :

public function Details($id){
        $demandes=DB::select('SELECT * FROM demande where id_demande=? ',[$id]);
        $buts=DB::select('SELECT * FROM but where id_demande=? ',[$id]);
        return view('details')->with(array('demandes'=>$demandes ,'buts'=>$buts));
    }

Web.php :

Route::get('/Details/{id}','DemandeController@Details')->name('Details');

Blade.php :

@extends('layouts.mainlayout')
@section('content')
//code
@endsection

The problem is the blade is not loading css and Js So you need to put this code in the <head> ----> <base href="/public">

0
votes

Run this..

php artisan ui bootstrap --auth

source: Laravel frontend docs

-1
votes

as answered above not only for resources that are called from the header in your blade but for effectiveness ensure that all other resources within your blade are also referenced using the asset() method such as when referencing images/ videos without your page.