So let me start off with giving you what I have in my controller index:
function index() {
//get all roles
$roles = Role::paginate(2);
return view('role.index', compact('roles'));
}
I have 3 roles. To test if paginate works I set it to 2. So far this works. for my blade:
@foreach($roles as $role)
<?php $count++ ?>
<div class="tr row jquery_update jquery_update_child">
<div class="td checkbox col-xs-2 ">
<label>
<input class="checkbox_ck" name="checkbox_{id}" type="checkbox" value="">
<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
</label>
</div>
<a class="iframe" href="">
<div class="td col-xs-2">
</div>
<div class="td col-xs-6">
</div>
<div class="td col-xs-2">
</div>
</a>
</div>
@endforeach
<div class="pagination_container">
</div>
This part works. I'm using colorbox to get popups. I load my show method from my controller in a iframe popup. my show method:
function show($id) {
//get the specific role
$role = Role::findorfail($id);
return view('role.show', compact('role'));
}
As you can see I don't use paginate because it is just 1 role, but I do have multiple profiles connected to this role. In my show contoller I show all the profiles connected to that role:
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>img</th>
<th>full name</th>
<th>Company</th>
</tr>
</thead>
<tbody>
<?php $count = 0;
use Illuminate\Pagination\LengthAwarePaginator;
$profiles = $role->profiles;
//Get current page form url e.g. &page=6
$currentPage = LengthAwarePaginator::resolveCurrentPage();
//Create a new Laravel collection from the array data
//Define how many items we want to be visible in each page
$perPage = 1;
//Slice the collection to get the items to display in current page
$currentPageSearchResults = $profiles->slice(($currentPage - 1) * $perPage, $perPage)->all();
//Create our paginator and pass it to the view
$paginatedSearchResults= new LengthAwarePaginator($currentPageSearchResults, count($profiles), $perPage);
?>
@foreach($paginatedSearchResults as $profile)
<?php $count++?>
<tr>
<td>
</td>
<td>
<img src="" alt=""/>
</td>
<td>
</td>
<td>
(Function )
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="pagination_container">
</div>
in my html browser the pagination does load correctly and I can see it visually
<ul class="pagination">
<li class="disabled"><span>«</span></li>
<li class="active"><span>1</span></li>
<li><a href="/?page=2">2</a></li>
<li><a href="/?page=2" rel="next">»</a></li>
</ul>
So when I click on (example) <li><a href="/?page=2">2</a></li>
then this brings me to another view. NOTE: there is the iframe url and browser url. The Iframe url is the one that is changing. If I manually change the url from my iframe to http://example.com/role/1/?page=2 then it does work.
So when I click on the tag is brings me to: http://example.com/company/1
I have no clue why this is going on?? any help would be appriciated!
via user7791653