//I tried to get count of( approved replies) and count of (category) in view as following but this is not work with me!!
In View:
@if($posts)
@foreach($posts as$post)
<p>No. approved replies=</p>
<p>No. category=
@endforeach
@endif
In Post controller:
public function index()
{
$posts=Post::all();
return view('Admin.posts.index',compact('posts'));
}
In Post model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $fillable=[
'title','body','category_id','photo_id'
];
public function user(){
return $this->belongsTo('App\User');
}
public function category(){
return $this->belongsTo('App\Category');
}
public function comments(){
return $this->hasMany('App\Comment');
}
}
///
In Comment model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $fillable=[
'post_id',
'photo',
'author',
'email',
'body',
'is_active'
];
public function replies(){
return $this->hasMany('App\CommentReply');
}
public function post(){
return $this->belongsTo('App\Post');
}
}
In CommentReply model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class CommentReply extends Model
{
protected $fillable=[
'comment_id',
'is_active',
'author',
'photo',
'email',
'body'
];
public function comment(){
return $this->belongsTo('App\Comment');
}
}
/////////////////////////////////////////////////////////////////////////////////
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire