Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel Query: orderBy not working with groupBy (with a joined table)

$receivedmessages = DB::table('messages')
    ->join('users', 'users.id', '=', 'messages.sender_id')
    ->select('messages.*', 'users.username')
    ->whereRaw('messages.id IN (SELECT MAX(messages.id) FROM messages GROUP BY receiver_id, sender_id)')
    ->where('receiver_id', Auth::user()->id)
    ->orderByDesc('messages.created_at')
    ->get();
Comment

PREVIOUS NEXT
Code Example
Php :: get datetime of excel cell in codeigniter 
Php :: ganti url phpmyadmin 
Php :: obtener datos de orden wordpress php 
Php :: automatically make created_by and updated_by using observer laravel 
Php :: laravel cors 
Php :: laravel load relationship including empty values 
Php :: php specific function to Unflatten array 
Php :: namespace autoload php 
Php :: laravel eloquent get current sequence value 
Php :: set modes magento 2 
Php :: dot after each character php 
Php :: Comment supprimer les éléments liés à WordPress oEmbed 
Php :: calculate average in eager loading laravel 
Php :: onbeforeunload com mysql php 
Php :: spatie sluggable not working 
Php :: multidimensional session-array 
Php :: php listen to select event 
Php :: woocommerce remove notification after some time 
Php :: convert code python to php 
Php :: laravel gigapay get single payout 
Php :: show real number and not exponential form php 
Php :: how to update xampp php version 
Php :: title active php 
Php :: PHP Installation broken - shows strange php code as response 
Php :: how to pass javascript variable to php 
Php :: Rewrite .php file without .php extension with .htaccess ULTIMATE SOLUTION 
Php :: Régler l’enregistrement automatique dans WordPress 
Php :: PHP 7 - Fatal error: Call to undefined method PDF::FPDF() 
Php :: php print array as string 
Php :: if data come from foreach loop and if there are same value then sum of this same value and pass it to variable in php 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =