Laravel未定义属性:stdClass :: $ id错误

时间:2016-11-25 11:03:52

标签: php forms laravel-5.2

我非常喜欢laravel,甚至一些小错误让我感到害怕..我从名为'student'的表中获取数据但是当我这样做时,我收到错误

  

未定义的属性:stdClass :: $ id

如果我在这里得到一些帮助,那就太好了..谢谢你

StudViewController.php

<?php
namespace App\Http\Controllers;
use DB;
use App\Http\Controllers\Controller;

class StudViewController extends Controller
{
    //
    public function index(){
      $users = DB::select('select * from student');
      return view('stud_view',['users'=>$users]);
   }
}

stud_view.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
<table border = 1>
         <tr>
            <td>ID</td>
            <td>Name</td>
         </tr>
         @foreach ($users as $user)
         <tr>
            <td>{{ $user->id }}</td>
            <td>{{ $user->name }}</td>
         </tr>
         @endforeach
      </table>
    </div>
</div>
@endsection

routes.php文件

Route::get('view-records','StudViewController@index');

1 个答案:

答案 0 :(得分:1)

试试这个......

@foreach ($users as $user)
 <tr>
    <td>{{ $user->Id }}</td>
    <td>{{ $user->Name }}</td>
 </tr>
 @endforeach