在CentOS系統上創建Laravel視圖,你需要遵循以下步驟:
composer create-project --prefer-dist laravel/laravel your_project_name
將your_project_name
替換為你的項目名稱。
resources/views
目錄。你可以使用文本編輯器(如vim、nano等)創建一個新的視圖文件。例如,創建一個名為example.blade.php
的視圖文件:cd resources/views
touch example.blade.php
example.blade.php
文件,并添加你想要顯示的內容。例如:<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example View</title>
</head>
<body>
<h1>Hello, this is an example view!</h1>
</body>
</html>
php artisan make:controller ExampleController
然后,在app/Http/Controllers/ExampleController.php
文件中添加一個名為showExampleView
的方法,該方法返回example.blade.php
視圖:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ExampleController extends Controller
{
public function showExampleView()
{
return view('example');
}
}
routes/web.php
文件中定義一個路由,將URL映射到控制器方法。例如:use App\Http\Controllers\ExampleController;
Route::get('/example', [ExampleController::class, 'showExampleView']);
現在,當你訪問http://your_server_ip_or_domain/example
時,你應該看到example.blade.php
視圖中的內容。