In my blade.php file that is displaying a single post is working perfectly well. In the blade I also have the access of the categories associated with the post i.e $post->categories
and is working too.
The single post that I'm displaying from the .blade.php with a title in the header has got only one category and that is football.
When I loop over the posts title associated with the category of the post being displayed from the .blade.php file using the code below it works well and I get the titles of the posts associated with the category football as expected!
@foreach($post->categories as $category)
@foreach($category->posts as $post)
<p>{{ $post->title }}</p>
<br>
@endforeach
@endforeach
MY CHALLENGE: I'd like to exclude the title of the post that is also the title of the post of being displayed so that I don't repeat a title at the bottom of my page that was already in the header of the page.
MY CONTROLLER!
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Model\user\post;
use Illuminate\Http\Request;
class PostController extends Controller
{
public function post(post $post)
{
return view('user.post', compact('post'));
}
}
MY Post Model
<?php
namespace App\Model\user;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public function tags()
{
return $this->belongsToMany('App\Model\user\Tag', 'post_tags')->withTimestamps();
}
public function categories()
{
return $this->belongsToMany('App\Model\user\Category', 'category_posts');
}
public function getRouteKeyName()
{
return 'slug';
}
}
My Category Model
<?php
namespace App\Model\user;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
public function posts()
{
return $this->belongsToMany('App\Model\user\post', 'category_posts');
}
public function getRouteKeyName()
{
return 'slug';
}
}
my Category_post Model
<?php
namespace App\Model\user;
use Illuminate\Database\Eloquent\Model;
class Category_post extends Model
{
public function posts()
{
return $this->belongsToMany('App\Model\user\Post', 'category_posts');
}
}
Please note that everything is working perfectly fine. When I loop over $category->posts title in my .blade.php file I get the posts title as expected. Now I just want to exclude the title of the post that is rendered by the blade.php file