app直下のcomment.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
//
protected $fillable = ['body'];
// $comment->post
public function(){
return $this->belongsTo('App\Post');
}
}
post.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
//
protected $fillable = ['title', 'body'];
public function comments(){
return $this->hasMany('App\Comment');
}
}
<h2>Comments</h2>
<ul>
@forelse ($post->comments as $comment)
<li>
{{ $comment->body }}
</li>
@empty
<li>No comments yet</li>
@endforelse
</ul>
@endsection
しまったーーーーーーーーー ファイル保存する前にmigrateしてバグってしまった。
なんてことを。。
まぁ、Laravelに慣れる、という目的は少し達成したので良しとしよう。
