I have two tables; Students and Grade. Students contains foreign key grade_id referencing Grade. For viewing students, I have used following code; Controller:
public function viewStudent()
{
$students=Student::all();
return $students('grade_id');
$grade = Grade::find($id, ['id', 'grade_name']);
return view('students.view',compact('students'));
}
View:
<tbody>
@foreach($students as $student)
<tr class="info">
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
@endforeach
</tbody>
Model:
class student extends Model
{
//
protected $fillable = ['first_name','middle_name','last_name','grade_id'];
}
It shows grade_id as i have called it. But I want grade_name instead of that. Can anyone help me?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WwwNf9
via IFTTT
Aucun commentaire:
Enregistrer un commentaire