Level 1
Feb 11, 2021
2
Level 1
Substitute a code id with corrispondent other field in separate table of coding
Hi which is the best way to do this I have 3 tables
Invoice table
namespace App;
use Illuminate\Database\Eloquent\Model;
class Invoice extends Model
{
/**
* The roles that belong to the invoice.
*/
public function shifts()
{
return $this->belongsToMany(Shift::class, 'invoice_shift')
->withPivot(['invoice_id','shift_id','shift_swapped_date','tas']);
}
}
Shift table
use Illuminate\Database\Eloquent\Model;
class Shift extends Model
{
/**
* The users that belong to the role.
*/
public function invoices()
{
return $this->belongsToMany(Invoice::class, 'invoice_shift');
}
}
In relation many to many
and I have a third table User
with id and name field
In table pivot invoice_shift i have a column where i save user ID
how can get user->name in substitution with user id in blade??
Have I to create another relationship many to many between user table and invoice_shit pivot table? O there are another method?
Thanks a lot
Please or to participate in this conversation.