为什么 css 和 bootstrap 没有加载到 Laravel 5.3?

Why css and bootstrap is not loading in Laravel 5.3?

这是我的路由文件...


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

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

    });

"ProfileControllers"就是这个...


    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');
        }
    }

这是视图文件...


    @extends('layout')

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

布局文件的头部是这样的...


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

当我访问 url "localhost:8000/profile/username" 时,显示了一个丑陋的 html,没有任何 css 网页.. .. 当我从路由文件中删除“/{username}”,并将其设为“/profile/username”并转到 "localhost:8000/profile/username"(并删除 $username 部分表单控制器),然后 css bootstrap 完美加载....

这里发生了什么?

我通过简单地将“/”放在 link

前面解决了这个问题
link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"
link rel="stylesheet" type="text/css" href="/css/app.css"

您可以将此行添加到 blade 文件的顶部。

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

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

希望有用!

在包含指向您的 bootstrap 文件的链接之前(或在 运行 加入 'npm command' 之前),您是否 运行 使用了 'php artisan migrate' 命令?

如果是这样,那么 运行 'php artisan migrate:rollback' 在 运行ning 'php artisan migrate' 之前(特别是如果您使用 'npm' 这样的库来引入您的依赖项,例如作为 'Bootstrap'),

解决方法是...

Comment out <link href="{{ asset('css/app.css') }}" rel="stylesheet"> and add following link into the app.blade.php

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

我运行下面的命令对我有用

作曲家要求ui重新laravel/ui

然后 运行

php artisan ui bootstrap

然后 运行 下面的 npm 命令

  1. npm i
  2. npm 运行 开发