Laravel: variable Undefined
im having a problem with my code.
I want to show a record of a student who entered, but I have
undefined on my view.blade
Here's my model
class Attendance extends Eloquent {
public function users()
{
return $this->belongsTo('User', 'id');
}
}
Here's my controller
public function viewstudentAttendance()
{
$students = Auth::user()->id;
//load view and pass users
return View::make('student.view')
->with('attendances', $students);
}
Finally, here's my 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
I think the problem is with my view or with how I declare the variable? Please help ?:(
0
source to share
1 answer
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
}
Inside your blade template, use:
@if ($studentCount > 10)
instead
@if ($students->count())
Your students are returning an ID as you might "count"
http://laravel.com/docs/4.2/eloquent
Inside your blade you kept doing if ($ students) bla bla just so you know his attendance
-> s ("attendance", $ students);
Attendance is the variable your blade sees, $ student is the data you click on the attendance for the blade
0
source to share