D
Size: a a a
D
K
VY
K
D
D
K
AH
$lastposts = Post::select('id', 'title','created_at', 'counter', 'category_id')
->where('id', '!=', $id)
->with('category')
->orderBy('created_at', 'DESC')
->limit(6)
->get();
$lastposts = Post::with('category')
->where('id', '!=', $id)
->latest('created_at')
->take(6)
->get(['id', 'title','created_at', 'counter', 'category_id']);
В сумме должно быть два запроса - один для таблицы posts и один для categoriesAH
category
в модели Post
?K
category
в модели Post
?public function category()
{
return $this->belongsTo('App\Category');
}
K
$lastposts = Post::with('category')
->where('id', '!=', $id)
->latest('created_at')
->take(6)
->get(['id', 'title','created_at', 'counter', 'category_id']);
В сумме должно быть два запроса - один для таблицы posts и один для categoriesK
AH
public function category()
{
return $this->belongsTo('App\Category');
}
K
public function show($slug, $id)
{
$post = Post::select('id','title','excerpt','body','created_at','counter', 'category_id')
->where('status', 1)
->findorFail($id);
$category = Category::where('slug', $slug)->firstorFail();
$article = $category
->posts()
->where('id', '!=', $id)
->orderBy('created_at', 'DESC')
->limit(5)
->get();
$lastposts = Post::with('category')
->where('id', '!=', $id)
->latest('created_at')
->take(6)
->get(['id', 'title','created_at', 'counter', 'category_id']);
return view('post.view', compact('post', 'article', 'lastposts'));
}
K
K
K
$category = Category::where('slug', $slug)->firstorFail();
$article = $category
->posts()
->where('id', '!=', $id)
->orderBy('created_at', 'DESC')
->limit(5)
->get();
K
AH
public function show($slug, $id)
{
$post = Post::select('id','title','excerpt','body','created_at','counter', 'category_id')
->where('status', 1)
->findorFail($id);
$category = Category::where('slug', $slug)->firstorFail();
$article = $category
->posts()
->where('id', '!=', $id)
->orderBy('created_at', 'DESC')
->limit(5)
->get();
$lastposts = Post::with('category')
->where('id', '!=', $id)
->latest('created_at')
->take(6)
->get(['id', 'title','created_at', 'counter', 'category_id']);
return view('post.view', compact('post', 'article', 'lastposts'));
}
/*
* В роутах дожно быть так:
*
* ->get('{category:slug}/{post}', 'YourController@show');
*/
public function show(Category $category, Post $post)
{
$articles = $category
->posts()
->where('id', '!=', $post->id)
->latest()
->take(5)
->get();
$lastposts = Post::with('category')
->where('id', '!=', $post->id)
->latest()
->take(6)
->get(['id', 'title', 'created_at', 'counter', 'category_id']);
/*$post->increment('counter');*/
return view('post.view', compact('post', 'articles', 'lastposts'));
}
AH