【发布时间】:2021-01-28 13:50:32
【问题描述】:
我想创建一个可以显示 user_id = user_id 登录的数据的页面 这是我的控制器,它从表中选择所有数据,我想用相应的登录用户 ID 过滤它
public function staffHome()
{
$posts = Post::latest()->paginate(5);
return view('staffHome', compact('posts'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
这是我的看法
@foreach ($posts as $post)
<tr>
<td class="text-center">{{ ++$i }}</td>
<td>{{ $post->title }}</td>
<td class="text-center">
<form action="{{ route('posts.destroy',$post->id) }}" method="POST">
<a class="btn btn-info btn-sm" href="{{ route('posts.show',$post->id) }}">Show</a>
<a class="btn btn-primary btn-sm" href="{{ route('posts.edit',$post->id) }}">Edit</a>
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Apakah Anda yakin ingin menghapus data ini?')">Delete</button>
</form>
</td>
</tr>
@endforeach
提前致谢
【问题讨论】:
-
通过阅读 laravel 的文档,您可以找到 where() 函数...