3

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 ?!

6
  • Is there a reason you not pointing the servers' document root to Laravel's public directory? Commented Apr 30, 2015 at 16:29
  • Can make it more clear please, I'm new with laravel !! Commented Apr 30, 2015 at 16:41
  • 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? Commented Apr 30, 2015 at 16:58
  • 3
    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. Commented Apr 30, 2015 at 17:03
  • Ok it's work well now, after adding this line <base href="localhost/laravel/public"> to <head> Thansks :) Commented Apr 30, 2015 at 17:12

5 Answers 5

17

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 :)

Sign up to request clarification or add additional context in comments.

Comments

1

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">

Comments

0

Run this..

php artisan ui bootstrap --auth

source: Laravel frontend docs

Comments

0

OK, its a old thread, but here is my solution for records.

I've put ../ in front of my existing resource e.g

<script src="js/front.js"></script>

became

<script src="../js/front.js"></script>

Comments

-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.