Hi Everyone, After inserting a company a record. I would like to retrieve the paginated page where the newly created is sitting. After the record is successfully inserted I redirect to a view that has a paginated list of companies that are sorted in alphabetical order.
So basically I'd like to look within the pagination collection for the company id of x and have it return the pagination page # that the where the record resides in the sorted list.
Any ideas?
public function show($id)
{
$companies = Company::companyNameAscending()->paginate(300);
// need the (paginated) page number that $id is going to be sitting on within $companies
$company = Company::findOrFail($id);
$notes = $company->notes()->dateCreatedDescending()->get();
$company_address = $company->companyAddress()->get();
$contacts = $company->contacts()->limit(100)->get();
return view('companies.show', compact('companies', 'company', 'notes', 'company_address', 'contacts'));
}
Totally, but for the system after a record is added I go to the newly created record. Which also has the paginated list of companies so a user can hop over to another record without leaving the page.
How could that be possible when the pagination calculations has to take place again and that record be properly placed in the correct position? Sorry just confused on what you are driving at.
Basically after a new record company is inserted I'd like that list of companies to automatically load the paginated page where the newly inserted company resides.
So let's say you have total 6 companies. Pagination is set to 2 records / page. The Company list is sorted Alphabetically.
Pre company paginated page list
Page 1
Company 1
Company 2
Page 2
Company 3
Company 4
Page 3
Company 5
Company 6
Post company paginated page list
Page 1
Company 1
Company 2
Page 2
Company 3
Company 3 new insert // show this item after insert is completed on the correct paginated page
Page 3
Company 4
Company 5
Page 4
Company 6
so i need to somehow figure out that Company 3 new insert resides on paginated page=3
Thanks for the reply @schir1964 I've made a quick test o what you were saying to do. It ends up taking a full second to generate the data from the Query which of course is to much. Any other ideas?
So in pushing this thought further i noticed something if i can figure out how to access it that will do the trick.
When doing a dump of a collection the item number is appended to the object name specifically #618 . Anyone know how to get access to that number? It does not seem to be stored in the object it's self an I haven't found the methods that help in the naming of the object in the collection.
This is a dump of the whole object for context. So, as of right now I'm trying to figure out what the #'s #314 and #618 represent and how I can access them. Noticing the numbers are next to objects only and not arrays. Any ideas?