Мне нужно выводить названия, вот что у меня в blade.php
@foreach($user->guilds as $guild)
<option value="{{$guild->id}}">{{$guild->name}}</option>
@endforeach
Вот такую ошибку у меня выдает Property [guilds] does not exist on this collection instance.
Вот что у меня в Controller
public function __invoke()
{
$user = User::all();
$guilds = Guild::all();
$userGuild = UserGuild::all();
return view('main.server.create', compact('user','guilds','userGuild'));
}
Вот какая у меня связь в БД
User
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id();
$table->unsignedBigInteger('guild_id')->nullable();
$table->foreign('guild_id','user_guild_fk')->on('guilds')->references('id');
$table->index('guild_id','user_guild_idx');
$table->rememberToken();
$table->timestamps();
User_Guild
Schema::create('user_guilds', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id();
$table->unsignedBigInteger('user_id')->nullable();
$table->unsignedBigInteger('guild_id')->nullable();
$table->index('user_id','user_guild_user_idx');
$table->index('guild_id','user_guild_guild_idx');
$table->foreign('user_id','user_guild_user_fk')->on('users')->references('id');
$table->foreign('guild_id','user_guild_guild_fk')->on('guilds')->references('id');
$table->timestamps();
Guild
Schema::create('guilds', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id();
$table->string('name');
$table->timestamps();