minions
2 years ago

Order by Short to Long

Posted 2 years ago by minions

Hello, I need help for get result from my query, my code is like this

//Keyword  = Leonardo Da Vinci 

$keyword = explode(' ', $request->keyword);
$db = Book::where('title', 'like', '%' . implode('%', $keyword) . '%')
            ->take(10)
            ->get();
$title_book = $db->pluck('title');

return $title_book;

and the output like this

Leonardo da Vinci: Complete Paintings and Drawings
Becoming Leonardo: An Exploded View of the Life of Leonardo da Vinci
Leonardo da Vinci
Who Was Leonardo da Vinci?

how to output query from short to long like this

Leonardo da Vinci
Who Was Leonardo da Vinci?
Leonardo da Vinci: Complete Paintings and Drawings
Becoming Leonardo: An Exploded View of the Life of Leonardo da Vinci

Please sign in or create an account to participate in this conversation.