Laravel 8 顯示數(shù)據(jù)

2021-07-17 16:47 更新

你可以把變量置于花括號中以在視圖中顯示數(shù)據(jù)。 例如,給定下方的路由:

Route::get('greeting', function () {
    return view('welcome', ['name' => 'Samantha']);
});

您可以像如下這樣顯示 name 變量的內(nèi)容:

技巧:Blade 的 {{ }} 語句將被 PHP 的 htmlspecialchars 函數(shù)自動轉(zhuǎn)義以防范 XSS 攻擊。

不僅可以顯示傳遞給視圖的變量的內(nèi)容,您亦可輸出任何 PHP 函數(shù)的結果。事實上,您可以在 Blade 模板的回顯語句放置任何 PHP 代碼:

The current UNIX timestamp is {{ time() }}.
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號