如何解决 Laravel 5.8 中紧凑的未定义变量错误
我想从表中的数据库中获取数据,但它在视图中显示未定义的变量错误,请帮助我解决这个问题
我的控制器
class showAttendanceController extends Controller
{
public function index()
{
$users=DB::select('select * from requests');
return view('showAttendance',compact('users'));
}
我的视图
@foreach ($users as $user)
<td>{{$user->date}}</td>
<td>{{$user->Name}}</td>
<td>{{$user->Misid}}</td>
<td>{{$user->semester}}</td>
<td>{{$user->Department}}</td>
<td>{{$user->section}}</td>
<td>{{$user->Attendance}}</td>
我的路线
Route::get('/showrecord','showAttendanceController@index')->name('showrecord');
I want to fetch data from database in table but it show me undefined variable error in view please help me to solve this problem
my controller
class showAttendanceController extends Controller
{
public function index()
{
$users=DB::select('select * from requests');
return view('showAttendance',compact('users'));
}
my view
@foreach ($users as $user)
<td>{{$user->date}}</td>
<td>{{$user->Name}}</td>
<td>{{$user->Misid}}</td>
<td>{{$user->semester}}</td>
<td>{{$user->Department}}</td>
<td>{{$user->section}}</td>
<td>{{$user->Attendance}}</td>
My Route
Route::get('/showrecord','showAttendanceController@index')->name('showrecord');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
控制器:
视图:
Controller:
View:
首先,最好使用迁移来创建表,以获得数据库一致性。
进一步尝试使用模型与数据库交互
例如
,然后您可以在控制器中使用它
first of all, it's better to create your table using migrations in order to have Database Consistency.
Further try to use models to interact with Database
for example
and then you can use it in your controller
首先,您必须在控制器中使用数据库,
而不是确认您的返回视图文件位置是否正确。例如,如果您的 showAttendence 文件位于您必须使用的文件夹内
first of all you have to use DB in your controller
than you have to confirm your return view file location is right or not.Exmple if your showAttendence file is inside a folder you have to use