未定义的变量$result(View:/resources/views/frontend/CustomerRequest



当我运行代码时,它会给出以下错误:"未定义的变量$result(View:/resources/views/frontend/CustomerRequestblade.php(";,任何人都可以提出任何解决方案。感谢

控制器:

public function index()
{
$result =  DB:: select('select * from form_request');
$result= form::all();
return view('frontend.CustomerRequest')->with('result', $result);
}

视图:

@foreach($result as $form)

<tr>
<td>{{ $form->id }}</td>
<td>{{ $form->name }}</td>
</tr>
@endforeach

路线:

Route::get('customerrequest',[PostsController::class, 'index']);

使用语法return view('frontend.CustomerRequest')->with('result', $result);是错误的,这种方式不会将变量传递到视图页。

相反,它应该是return view('frontend.CustomerRequest', compact('result');

所以把你的控制器功能改成这个

public function index()
{
$result =  DB:: select('select * from form_request');
$result= form::all();
return view('frontend.CustomerRequest', compact('result');
}

现在,在您的视图文件中,您应该能够访问$result变量。

相关内容

最新更新