laravel-mongodb
laravel-mongodb copied to clipboard
How to get attach attributes from belongsToMany relationship ?
- Laravel-mongodb Version: 3.8.4
- PHP Version: 7.4.12
- Laravel: 8.55 (lastest)
- Database Driver & Version: mongodb/mongodb 1.9
Description:
Steps to reproduce
Project Model
class Project extends Model
{
use HasFactory;
protected $guarded = ['_id'];
public function socials(){
return $this->belongsToMany(Social::class)->withPivot('link');
}
}
Socials Model
class Social extends Model
{
use HasFactory;
protected $guarded = ['_id'];
public function projects(){
return $this->belongsToMany(Project::class);
}
}
Tinker
$project = \App\Models\Project::create([
'name' => 'Project Name',
'website' => 'https://projectwebsite.com'
]);
$project->socials()->attach(' social _id ', ['link' => 'https://facebook.com/myproject']);
Result
$project = \App\Models\Project::first();
foreach($project->socials as $social){
var_dump($social->pivot->link); //null
var_dump($social->pivot); //null
}
Is this package support pivot attributes ?
Any update for this feature?