Lets assume, that we have Users and Types, and pivot type_user tables ready. We have done models User and Type relationship.
How to display all records in Types table one by one, and its Users assigned?
How to display all records in Types tables, which is of type 1 or type 2
Can you give me good source of example codes?
Users
id name
1 Name1
2 Name2
Types
id name
1 Type1
2 Type2
type_user
id name_id type_id
1 1 1
2 1 2
3 2 1
4 2 2
How to display example screen :
Names | Types
-------------------------
Name1 | Type1 and Type2
Name2 | Type1 and Type2
I don't know exactly your question. But may be it can help you.
// User Model
public function types()
{
return $this->belongsToMany(Type::class, 'types');
}
// Now you can loop them.
foreach ($user->types as $type) {
echo $type->name;
}