我剛開始學習laravel框架,並在這裏有一個奇怪的情況。查看不會在Laravel返回任何內容
都在我的web.php
首先我有這樣的代碼:
<?php
Route::get('/', function() {
return view('welcome');
});
Route::get('users', ['uses' => '[email protected]']);
在我UsersController.php
文件我有這樣的代碼:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UsersController extends Controller
{
public function index(){
return view('users.index');
}
}
我有一個文件在目錄views/users
名爲index.blade.php
具有與默認welcome.blade.php
相同的內容。但是,當我嘗試return view('users.index');
沒有結果(沒有錯誤,或文本),但當我嘗試return view('welcome');
它工作得很好。
目錄和文件確實存在。 我正在使用Macbook Pro。
welcome.blade.php
和/users/index.blade.php
內容(默認歡迎頁面):
<!doctype html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Raleway', sans-serif;
font-weight: 100;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 12px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@if (Auth::check())
<a href="{{ url('/home') }}">Home</a>
@else
<a href="{{ url('/login') }}">Login</a>
<a href="{{ url('/register') }}">Register</a>
@endif
</div>
@endif
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<div class="links">
<a href="https://laravel.com/docs">Documentation</a>
<a href="https://laracasts.com">Laracasts</a>
<a href="https://laravel-news.com">News</a>
<a href="https://forge.laravel.com">Forge</a>
<a href="https://github.com/laravel/laravel">GitHub</a>
</div>
</div>
</div>
</body>
</html>
如果視圖不存在,laravel將拋出一個錯誤。如果您只看到白頁,可能是因爲您的錯誤未顯示。檢查日誌文件是否有錯誤。 '存儲/日誌/ laravel.log'或您的PHP默認日誌文件。嘗試拼寫錯誤的視圖名稱,並檢查結果,你看到一個錯誤? – Hamoud
@Hamoud當我拼錯視圖名稱時,也只有一個白色頁面。 'Storage/logs/laravel.log'(文件不存在)並沒有存儲在我的默認php日誌文件中。 – semkius
然後,肯定會顯示一個不顯示的錯誤。檢查您的.env文件並確保它具有以下值: APP_ENV = local APP_DEBUG = true APP_LOG_LEVEL = debug – Hamoud