Hi!
Does anybody have an idea of how to do pagination on a page whereby in a data table, i'm displaying data from multiple tables?
I've pasted below, the algorithms that i'm using and please note that it is working fine but now i want to add pagination to that page, so does anybody know how i could modify my controller or view so that i can achieve that?
Thank you in advance!
In my controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Http\Controllers\Controller; use DB;
class DashboardController extends Controller {
public function index(Request $request)
{
$dataFirst = DB::table('firsts')
->join('account_connections', 'firsts.ftId', '=', 'account_connections.ftId')->get();
$dataSecond = DB::table('seconds')
->join('account_connections', 'seconds.trId', '=', 'account_connections.trId')->get();
$dataThird = DB::table('thirds')
->join('account_connections', 'thirds.geId', '=', 'account_connections.geId')->get();
return view('dashboard')
->with('dataFirst', $dataFirst)
->with('dataSecond', $dataSecond )
->with('dataThird', $dataThird )
->with('i', ($request->input('page', 1) - 1) * 9);
}
}
In my view:
<thead>
<tr>
<th>No</th>
<th>My Team</th>
<th>Website</th>
</tr>
</thead>
@foreach($dataFirst as $dataFirst)
@if(Auth::user()->id == $dataFirst->user_id)
<tbody>
<tr>
<td>{{ ++$i }}</td>
<td>{{ $dataFirst->first_name}} {{ $dataFirst->last_name}}</td>
<td>{{ $dataFirst->website}}</td>
</tr>
</tbody>
@endif
@endforeach
@foreach($dataSecond as $dataSecond )
@if(Auth::user()->id == $dataSecond ->user_id)
<tbody>
<tr>
<td>{{ ++$i }}</td>
<td>{{ $dataSecond ->first_name}} {{ $dataSecond ->last_name}}</td>
<td>{{ $dataSecond ->website}}</td>
</tr>
</tbody>
@endif
@endforeach
@foreach($dataThird as $dataThird)
@if(Auth::user()->id == $dataThird->user_id)
<tbody>
<tr>
<td>{{ ++$i }}</td>
<td>{{ $dataThird->first_name}} {{ $dataThird->last_name}}</td>
<td>{{ $dataThird->website}}</td>
</tr>
</tbody>
@endif
@endforeach