私のデータベースには3つのテーブルがあります。 3つのテーブルデータをすべて1ページに表示したいLaravel - 複数のテーブルのデータを1ページに表示
Student.php
public function hobbies() {
return $this->hasMany(Student::class);
}
Hobbie.php
public function student()
{
return $this->belongsTo(Student::class);
}
Controller.php
$students->name= request('name');
$students->address = request('address');
if($students->save())
for ($i=0; $i < count(request('hob')); ++$i)
{
$hobbies = new Hobby;
$hobbies->name= request('hob')[$i];
$students->hobbies()->save($hobbies);
}
View.blade.php $ students-> hobbies() - >ホブ;
ただし、趣味は表示されません。適切な解決策は何ですか?
'request( 'name')'は何ですか? – C2486
どのバージョンのlaravelを使用していますか? –
趣味の学生データが必要な場合など、詳しく説明してください。 –