当我试图把变量放入我的Laravel代码时,我得到了错误。我知道你应该定义路由中的变量,但我一无所获。我正在尝试建立一个内容管理系统的网站。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
<div class="row align-items-center mr-5">
@foreach($abouts as $about)
<div class="col-lg-6 pl-lg-5 ">
<h3 class=" font-weight-bold">About Us</h3>
<p class="text-justify pt-3 mr-5">Test.</p>
<p class="text-justify pt-3 mr-5">Test.</p>
</div>
</div>
@endforeach
</ul>
</body>
</html>这是我在web.php文件中使用的代码
Route::get('/about', [App\Http\Controllers\AboutController::class, 'about'])->name('about');这是我在AboutController文件中使用的代码
public function about()
{
return view('/about');
}发布于 2021-08-15 17:04:46
由于您希望访问刀片模板中的$abouts变量,因此应该在呈现about模板时传递该变量。
应该是这样的
public function about()
{
// Here the variable which contain the data
$abouts = []; // And pass some data
// Here you pass all data for the $about variable to template which is rendered
return view('/about', compact('abouts'));
}发布于 2021-08-15 17:05:16
在about控制器中,您需要将数据绑定到视图
use App\Models\About;
public function about()
{
$abouts = About::all();
return view('/about',compact('abouts'));
}https://stackoverflow.com/questions/68793609
复制相似问题