试图获取非对象的属性(查看:C:\ Program Files \ Ampps \ www \ films \ resources \ views \ home.blade.php)

时间:2018-04-15 16:29:46

标签: php laravel laravel-blade laravel-authorization

我在Auth:: user()->name时出错,如果删除此div并使用表格代码运行,则错误相同。这是home.blade.php。我在另一个应用程序上运行相同的代码,但不是这个。

@extends('layouts.app')
@section('content')
<div class="container">

  <div class="card">
    <div class="card-header bg-dark text-light">
      <h5 class="card-title">User dashboard for {{Auth::user()->name}}</h5>

      <a href="#" class="btn btn-danger" role="Button" style="float:right">Settings</a>

    </div>
    <div class="card-body">
      <div class="row">
        <div class="col-md-8">
          <table class="table table-striped">
            <tbody>
              <tr>
                <th>Movies you've rated </th>
                <td>{{Auth::user()->ratings->count()}}</td>
              </tr>
                <tr>
                  <th>Movies you've rated</th>
                  <td><ul>
                    @foreach(Auth::user()->ratings as $rating)<li>{{$rating->movie->title}} (rating {{$rating->rating}} /5)</li>
                    @endforeach
                  </ul></td>
                </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <a href="{{route('movies.index')}}" class="btn btn-danger" role="Button">Back</a>
  </div>

@endsection

1 个答案:

答案 0 :(得分:0)

  

您的控制器文件中缺少auth外观。

只需将此行代码放入控制器文件中即可 use Auth;