Dear all,
I am new to laravel and I have been following the tutorials and in chapter 31 relationships many to many I have an issue and I haven't been able to find a solution
I have defined my relationships in this way:
/********* Article.php *********/
'''<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
public function getRouteKeyName()
{
return 'slug';
}
public function tags()
{
return $this->belongsToMany(Tag::class);
}
}'''
/********* Tag.php *********/
'''<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model
{
public function articles()
{
return $this->belongsToMany(Article::class);
}
}'''
After populating the 3 tables articles, tags and article_tag with data and testing with tinker I am able to get some results when I use $tag->articles but whenever I use $article->tags it just return null even when the data is there
Does anybody has a clue what should I check?
Thank you in advance for your support
Have a good day