【发布时间】:2015-05-15 08:24:20
【问题描述】:
我的代码有问题。
我想显示登录但我有一个学生的记录
我的 view.blade 上的未定义变量
这是我的模型
class Attendance extends Eloquent {
public function users()
{
return $this->belongsTo('User', 'id');
}
}
这是我的控制器
public function viewstudentAttendance()
{
$students = Auth::user()->id;
//load view and pass users
return View::make('student.view')
->with('attendances', $students);
}
最后是我的观点。刀片
@extends('layouts.master')
@section('head')
@parent
<title>View Attendance</title>
@stop
{{ HTML::style('css/bootstrap.css'); }}
@section('content')
</ul>
@if ($students->count())
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
</tr>
</thead>
<tbody>
@foreach ($students as $students)
<tr>
<td>{{ $students->id }}</td>
<td>{{ $students->firstname }}</td>
<td>{{ $students->lastname }}</td>
@endforeach
</tr>
{{ HTML::script('js/bootstrap.js'); }}
</tbody>
</table>
@else
There are no attendance recorded yet
@endif
@stop
我认为问题在于我的观点或我如何声明变量?请帮忙? :(
【问题讨论】:
-
@if ($students->count()) ??
-
您将数据发送为
attendances而不是students -
@foreach($students 为 $student)
标签: laravel laravel-4 eloquent declaration laravel-5