I think you would do something like this (assuming you have a User model):
User::leftJoin('classifieds', 'users.id', '=', 'classifieds.user_id')
->whereRaw("classifieds.dates > DATE_SUB(NOW(), INTERVAL 43200 MINUTE) AND classifieds.user_id = $userid")
->select(
'users.id', 'users.first_name', 'users.last_name', 'users.avatar',
'classifieds.title', 'classifieds.dates', 'classifieds.file_name', 'classifieds.description'
)
->get();
Untested, so someone please correct me if I'm wrong.
You could either do this directly in your controller (nothing really wrong with that), but if you think you're gonna need it in multiple places, maybe you wanna look into local query scopes. For example, on your User model:
public function scopeSomeScope($query, $userID) {
return $query::leftJoin('classifieds', 'users.id', '=', 'classifieds.user_id')
->whereRaw("classifieds.dates > DATE_SUB(NOW(), INTERVAL 43200 MINUTE) AND classifieds.user_id = $userID")
->addSelect(
'users.id', 'users.first_name', 'users.last_name', 'users.avatar',
'classifieds.title', 'classifieds.dates', 'classifieds.file_name', 'classifieds.description'
);
}
And then you'd call it as:
User::someScope()->get();
Do note the use of ->addSelect() instead of just ->select(). This allows you to add onto your select statement instead of overriding it entirely, if you choose to add more to it when interacting with the method. For example:
User::select('created_at')->someScope()->get();
You can read more about the syntax under the Joins section on Query Builder docs page: https://laravel.com/docs/5.6/queries#joins