我在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
答案 0 :(得分:0)
您的控制器文件中缺少
auth
外观。
只需将此行代码放入控制器文件中即可
use Auth;