我的代码有问题。
我想要显示登录但我有
的学生的记录我的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);
}
最后这是我的view.blade
@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
我认为问题在于我的观点或我如何声明变量?请帮忙? :(
答案 0 :(得分:0)
public function viewstudentAttendance() {
//This code turns ID ONLY Check the website out for a code that retrieves data so you can loop it.
$students = Auth::user() - > id;
//Code that counts number of student
$studentCount = XXX(Google It)
//load view and pass users
return View::make('student.view') - > with('attendances', $students);
//Return StudentCount too
}
在您的刀片模板中,使用:
@if ($studentCount > 10)
而不是
@if ($students->count())
你的学生正在归还身份证,你怎么能“数”
http://laravel.com/docs/4.2/eloquent
在你的刀片内你一直在做($学生)bla bla,只是为了让你知道它的出席情况
- &gt; with('attendances',$ students);
出勤率是您的刀片将看到的变量,$ student是您正在推动刀片出席的数据