Sunday, April 16, 2017

How to show 2 tables data in 1 view using laravel?

There is two tables (one is Users and second is Branches). I want to show the Branch with its Branch Admin Name.And the branch Admin info is save in users table. There is an error When i am trying to show the data of Two table in one view. Tell me How i manage this issue.

View:

<div class="branches col-xs-12 col-sm-12 col-md-9 col-lg-9">
    <input type="text" class="pull-right form-control search" placeholder="Search">

    <div class="spaces"></div>

    <table class="table table-bordered">
        <thead>
        <tr>
            <th>
                BranchName
            </th>
            <th>
                BranchAdmin
            </th>
            <th>
                Email
            </th>
            <th>
                Contact
            </th>
            <th>
                Location
            </th>
            <th>
                Action
            </th>
        </tr>
        </thead>
        <tbody>
        @foreach($branch as $brnch)
            <tr class="branchies-row">
                <td>
                    
                </td>
                @foreach($user as $users)
                    <td>
                        
                    </td>
                @endforeach
                <td>
                    
                </td>
                <td>
                    
                </td>
                <td>
                    
                </td>


                <td>
                    <a data-id="" class="delete-branch">Delete</a> /
                    <a href="/branch/edit/">Edit </a>
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>
</div>

Controller:

public function getBranchinfo(){
    $user = User::where('type', '=', 'BranchAdmin');
    $branch = Branch::all();
    return view('Branch.branchinfo')->with('branch',$branch)->with('user', $user);
}

Model:

public function branch(){
    return $this->hasOne('App\Branch', 'user_id', 'id');
}



via Haider

Advertisement