Sorting paginate in CakePHP

0

I've never heard of CakePHP, I'm having a bit of trouble adjusting a purchased script where the developer does not support it.

This code is responsible for listing some image records saved in the database.

        public function choose(Request $request)
        {
            $memes = $this->meme->paginate(10000);

            if ($request->has('ajax')) {
                return $this->jsonPagination($memes, view('ext-meme::partials.memes', compact('memes')));
            }

            return view('ext-meme::choose', compact('memes'));
        }

They are listed in ascending order according to what they were entered into the bank.

What would be the code to list in reverse order? The last records being displayed first.

    
asked by anonymous 26.09.2017 / 17:46

1 answer

0

To sort descending use 'DESC' and to list from top to bottom use 'ASC'.

    public function choose(Request $request)
    {
        $memes = $this->meme->paginate(10000)->order(['nomeColuna' => 'ASC']);;

        if ($request->has('ajax')) {
            return $this->jsonPagination($memes, view('ext-meme::partials.memes', compact('memes')));
        }

        return view('ext-meme::choose', compact('memes'));
    }
    
26.09.2017 / 18:12