Reputation: 7175
I want to join two tables in laravel 5.3 and fetched the value in template page .now i caught error.I have two table names as users and department.$queries = DB::getQueryLog();
return the query what I want exactly as select users.*, department.name as dept_name from users inner join department on users.department_id = department.id
for the following query.this will return the error
ErrorException in Macroable.php line 74: Method links does not exist. (View: C:\wamp64\www\testLaravel\TestTravel\resources\views\approval_view.blade.php)
BadMethodCallException in Macroable.php line 74: Method links does not exist.
controller
class travelApprovalController extends Controller {
public function index(){
//$users = DB::table('passenger')->paginate(2);
$users = DB::table('users')
->join('department', 'users.department_id', '=', 'department.id')
->select('users.*', 'department.name as dept_name')
->get(); //->paginate(2)
return view('approval_view',['users'=>$users]);
}
approval.blade.php
@foreach ($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td><a href="#" class="viewPopLink" role="button" data-id="{{ $user->id }}" data-toggle="modal" data-target="#myModal">{{ $user->dept_name }}<a></td>
<td>{{ $user->dept_name }}</td>
<td>{{ $user->name }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
{{$users->links()}}
Upvotes: 0
Views: 2355
Reputation: 3658
try this
$users = DB::table('users')
->join('department', 'users.department_id', '=', 'department.id')
->select('users.*', 'department.name as dept_name')
->paginate(2);
Upvotes: 4
Reputation: 2736
Use like this
@foreach ($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td><a href="#" class="viewPopLink" role="button" data-id="{{ $user->id }}" data-toggle="modal" data-target="#myModal">{{ $user->dept_name }}<a></td>
<td>{{ $user->dept_name }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->links }}</td>
</tr>
@endforeach
OR
{{$users[0]->links()}}
Upvotes: 2