Answer the question
In order to leave comments, you need to log in
How to do proper Laravel pagination?
I have a template in which an Ajax view is displayed.
Ajax sends a POST request with a company id here:
Route::post('/market/getCompany', ['as' => 'getCompany', 'uses' =>'[email protected]']);
public function getCompany(Request $request)
{
$company = Company::where('id', $request->id)->first();
if(isset($company)){
$articles = $this->getArticles();
return view('layouts.market', compact('company','articles'));
}
return 'no results';
}
public function getArticles()
{
$articles = Articles::orderBy('price','desc')->simplePaginate(30);
$articles->withPath('/market/articles');
return $articles;
}
getCompany(); return 'no results';
Route::get('/market/articles', ['as' => 'getArticles', 'uses' =>'[email protected]']);
Answer the question
In order to leave comments, you need to log in
Hello.
1) if you resolve pagination at a separate address / request, then explicitly pass the page indication in the method:
https://github.com/laravel/framework/blob/master/s...
Otherwise, it takes the default value. On the main url, you always need to send all the data both on the current page and on your company id. But keep in mind that with your design, you will always receive a view with different data. Accordingly, you will need to replace the entire html. I would do it differently (see below)
2) by design, the solution looks strange. I would separate getting the view and getting the data. Then the comment from point 1 will probably become irrelevant.
3) in the database there is a request to check the existence of exists. If you do not use this data anywhere then, then you make a too bold request in vain.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question