Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why css and bootstrap is not loading in Laravel 5.3?

This is my route file...


    Route::group(['middleware' => ['auth']], function(){

        Route::get('/profile/{username}', 'ProfileControllers@getProfile');

    });

The "ProfileControllers" is this...


    namespace App\Http\Controllers;
    use DB;
    use App\User;
    use Illuminate\Http\Request;

    class ProfileControllers extends Controller
    {
        public function getProfile($username)
        {
            $user = DB::table('users')->where('username','=', $username)->get();
            return view('web.profile');
        }
    }

And this is the view file...


    @extends('layout')

    @section('content')
        This is your profile
    @stop

And The head of the Layout file is this...


    link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"
    link rel="stylesheet" type="text/css" href="css/app.css"

When I go to the url "localhost:8000/profile/username" and a ugly html without any css webpage is showing.... when I remove "/{username}" from route file, and make it "/profile/username" and go to the "localhost:8000/profile/username" (and also remove the $username part form controller) , then css and bootstrap loads perfectly....

What is happening here?

like image 684
Abu Zakaria Avatar asked Oct 09 '16 13:10

Abu Zakaria


2 Answers

I fixed this issue by simply putting '/' in front of the link

link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"
link rel="stylesheet" type="text/css" href="/css/app.css"
like image 180
anoynmous Avatar answered Oct 02 '22 13:10

anoynmous


You can add this line at the top of the blade file.

{{ HTML::style('css/app.css') }}

OR

link rel="stylesheet" href="{{ url('css/bootstrap.min.css') }}"

Hope it works!

like image 37
Shweta Avatar answered Oct 02 '22 13:10

Shweta