mercredi 1 juin 2016

Display name instead of id. Laravel

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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire