Laravel:未定义的变量 [英] Laravel: Undefined variable

查看:1816
本文介绍了Laravel:未定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有问题

我想显示登录的学生的记录,但我有一个

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

未定义的变量在我的view.blade

这是我的模型

class Attendance extends Eloquent {
  public function users()
  {
    return $this->belongsTo('User', 'id');
  }
}

这是我的控制器 / p>

Here's my Controller

public function viewstudentAttendance()
{
$students = Auth::user()->id;

    //load view and pass users  
    return View::make('student.view')
        ->with('attendances', $students);   
}

最后这里是我的view.blade


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? :(

推荐答案

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)

而不是

@if ($students->count())

您的学生正在返回身份证件,您如何计数

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

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

在你的刀片中,你一直在做,如果($学生)bla bla,只是为了让你知道这是参加者

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

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

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

出席人数是您的刀片可以看到的变量,$ student是您正在推送刀片的数据。

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

这篇关于Laravel:未定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆