dimanche 18 novembre 2018

how to join the two table in laravel 5.4

I am learning laravel 5.4. But I have stuck at one place.

I have two tables coursenames and branchnames.

branchnames table contains: id, branchname, course_id

coursenames table contains: id, coursename

coursename has unique name, and course_id of branchnames has id of coursename, which can be repeat.

My BranchNameController is:

public function index()
{
    $branchname = branchname::all();
    $coursename = coursename::all();
    return view('admin.branchname',compact('branchname','coursename'));
}

branchname.blade.php is:

<tbody>
@foreach($branchname as $branchnames)
<tr>
<td></td>
<td></td>

</tr>
@endforeach     
</tbody>

I want to show course name instead of . How it can be done?

model branchname.php is:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class branchname extends Model
{
//
}

model coursename.php is:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class coursename extends Model
{
//
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire