I'm having trouble getting data. I want to do the process of skipping the next page with pagination after acquiring about 40 items in the latest order and getting 5 items on the screen.
However, I got the old 5 out of 40, and I can only get the old 5 in the latest order. If I paginate, the date is off and I can't get the data well.
More specifically, there is data from January to October this year. What I want to realize is that I want to get the latest data from October, and now I only have the latest order from February to January.
index.blade.php
$blogs = $tag->blogs ()->action ()->sort ([
'direction' =>'DESC',
'sort' =>'arrange'
])->take (5)->get ();
<ul>
{{-{{dd ($blogs)}}-}}
@foreach ($blogs->splice (1)->sortByDesc ('release_date') as $blog)
<li>
slug}}/detail/{{$blog->id}} ">
<span>{{$blog->release_date}}</span>
{{$blog->title}}
<p><span>Read article</span></p>
</li>
@endforeach
blog.php
public function scopeSort ($query, $data = [])
{
foreach ($data as $key =>$val) {
// field filter
if (in_array ($key, $this->filterFields))
$query->where ($key, $val);
// field sort
if ($key === 'sort') {
if (! empty ($data ['direction'])) {
if (in_array ($data ['sort'], $this->sortFields))
$query->orderBy ($data ['sort'], $data ['direction']);
}
}
}
return $query;
As a supplement, the first one gets old data, and the second and subsequent ones get the latest data.
I have tried
If the contents of task (5) are changed to 40, the latest of 40 cases will come out, but 40 cases will be output and it will not work.
Also, when using sortByDesc, we get the old 5 out of 40, and we can't get the old 5 only in the latest order.
If there is any missing information, please let me know again. Thanks for your response.
-
Answer # 1
Related articles
- php - laravel detailed screen screen creation foreach statement plural form undefined error
- php - please tell me how to modify/add multiple data with laravel upsert
- php - the controller specified in laravel apiresource cannot be found
- php - laravel controller
- php - laravel parent view file function receiving and routing
- php - [laravel] command execution using guzzle is not possible
- php - i can't access the value i got using get in laravel from view
- php - laravel page can no longer be moved
- php - date format doesn't work in laravel unit tests
- php - [laravel 6] regular expression validation "|" handling
- php - laravel: value obtained by pluck cannot be obtained by foreach
- php - laravel i want to implement routing with multiple urls
- php - about gate by the value of laravel relation destination
- php - [laravel] the modal is not displayed
- php - how to work with laravel collection objects
- php - issuance of order reception number about good way
- php - how to output by classifying by staff area in laravel
- php - i want to prevent escaping when outputting {{}} with laravel echo
- php - laravel relation cannot be defined
- php - how to get when model of laravel is view instead of table
- php : Notification cannot be handled due to "ERROR: Class'App \ Http \ Controllers \ Api \ Firebase \ Factory' not found" error
- php - i want to read the exif information of an image with exif_read_data ()
- php - about laravel route
- php - when accessing the web application in lan from a pc in another lan, it cannot be referenced how can i make this visible?
- php - error in laradock docker-composeyml
- php - trying to access array offset on value of type null how to avoid
- php - i want to display the image file saved in the storage folder on the page
- php - why is the error statement returned in the url even though i wrote it with try catch?
- i want to get rid of the no route to host error in php file_get_contents ()
- php - laravel: i don't know how to send a variable from the controller
Use the paginate method.
https://readouble.com/laravel/5.8/en/pagination.html
Acquire ◯ out of ◯ cases
For, use the method at the bottom of the reference page.