0

im having a problem with my code.

I want to show the record of the student who login but im having an

undefined variable 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 how i declare the variable? Please help? :(

3
  • @if ($students->count()) ?? Commented Mar 12, 2015 at 23:37
  • you are sending the data as attendances and not students Commented Mar 12, 2015 at 23:41
  • @foreach ($students as $student) Commented Mar 12, 2015 at 23:46

1 Answer 1

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
}

Inside your blade template, use :

@if ($studentCount > 10)

instead of

@if ($students->count())

Your students is returning ID, how could you "Count"

http://laravel.com/docs/4.2/eloquent

Inside your blade you kept doing if($students) bla bla, just to let you know it's attendances

->with('attendances', $students);

Attendances is the variable your blade will see, $student is the data you are pushing into attendances for blade

Sign up to request clarification or add additional context in comments.

2 Comments

THANK YOU! and sorry about that hehe
no Problem! Was in your situation before ! & got slapped asking stupid question here LOL!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.