$items = DB::table('table')
->whereYear('created_at', 2021)
->selectRaw('month(created_at) month, count(*) count')
->groupBy('month')
->get();
public function lastMessage()
{
return $this->hasOne('App\Models\Message','chat_id', 'id')->latest();
}
$chats = Chat::with('lastMessage')->get();
@foreach ($chats as $chat)
{{ $chat->lastMessage->name }}
@endforeach
$users=User::orderBy('created_at', 'desc')->get();
$lastUsers = $users->unique('country')->take(10);