我是 laravel 的新手,我只是创建一个简单的应用程序,用户可以在其中登录和注册,然后在登录后在仪表板中写帖子,我试图在仪表板中显示用户帖子数据,该数据保存在数据库中,但是我收到此错误:
未定义变量:posts(视图:C:\xampp\htdocs\practiseapp\resources\views\dashboard.blade.php)
我想我已经定义了帖子,我不知道出了什么问题,任何帮助将不胜感激谢谢....
我的仪表板:
@extends('layout.master')
@section('content')
<div class="col-sm-6 col-sm-offset-3">
<header><h3>What do you wanna say</h3></header>
<form method="post" action="{{route('post.create')}}">
{{csrf_field()}}
<div class="panel-body">
<div class="form-group">
<textarea class="form-control" name="body" id="body" rows="5" placeholder="Enter your post">
</textarea>
</div>
<button type="submit" class="btn btn-primary">Create post</button>
</form>
</div>
</div>
<section class="row-posts">
<div class="col-md-6 col-sm-offset-3">
<header><h3>Other people posts</h3></header>
@foreach($posts as $post)
<article class="post">
<p>{{ $post->body }}</p>
<div class="info">
posted by {{ $post->user->name}} on {{$post->created_at}}
</div>
<div class="interaction">
<a href="#">Like</a>|
<a href="#">Disike</a>|
<a href="#">Edit</a>|
<a href="#">Delete</a>
</div>
</article>
@endforeach
</div>
</section>
@endsection
达令说
神不在的星期二