I have the following inside Stdent Model:
public function disciplines() {
return $this->belongsToMany(Discipline::class, 'student_discipline_classroom', 'student_id', 'discipline_id')
->withPivot('classroom_id')
->withTimestamps();
}
it give me a return
array:5 [▼ // routes\web.php:89
0 => array:6 [▼
"id" => 8
"name" => "Práticas Extensionistas Integradoras III"
"teacher" => 1
"created_at" => "2024-10-31T10:56:15.000000Z"
"updated_at" => "2024-10-31T10:56:15.000000Z"
"pivot" => array:5 [▼
"student_id" => 2
"discipline_id" => 8
"classroom_id" => 2
"created_at" => "2024-10-31T10:56:19.000000Z"
"updated_at" => "2024-10-31T10:56:19.000000Z"
]
]
1 => array:6 [▼
"id" => 9
"name" => "Gestão Ambiental e Desenvolvimento Sustentável"
"teacher" => 1
"created_at" => "2024-10-31T10:56:15.000000Z"
"updated_at" => "2024-10-31T10:56:15.000000Z"
"pivot" => array:5 [▼
"student_id" => 2
"discipline_id" => 9
"classroom_id" => 3
"created_at" => "2024-10-31T10:56:19.000000Z"
"updated_at" => "2024-10-31T10:56:19.000000Z"
]
]
.....
Bu i need of the field code (not is id) from classroom table.
What i have that ro change?
I am calling it so:
$students = Student::find(2);
dd($students->disciplines->toArray());
i reply that i wish this like
[
Array
(
[0] => Array
(
[discipline] => Expressão Gráfica
[classroom] => ENG. SOFT 1A 20242 S
)
[1] => Array
(
[discipline] => Introdução à Engenharia
[classroom] => ENG. SOFT 1A 20242 S
)
...