You need to actually complete the queries:
$pastRegistrations = $user->registrations()->with('event')->where('end_date', '<', now())
->get();
$nextRegistrations = $user->registrations()->with('event')->where('end_date', '>', now())
->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a UserController that has the index() method that should get all the registrations in congresses by a user and for each registration get the congress details (title and date). So that is possible to show in the view "users.index" the congress title, date and registration date of all user registrations in congresses.
The congresses table has a column "end_date", if the "end_date" is still in past it means that the congress not end yet, otherwise it means that the congress already end.
So I have the index method below to get the past registrations of a user in congresses and the enxt registrations of the user. But in the view is not appearing any result. Do you know why?
// index method:
class UserController extends Controller
{
public function index(Request $request){
$pageLimit = 5;
$user = $request->user();
$pastRegistrations = $user->registrations()->with('event')->where('end_date', '<', now());
$nextRegistrations = $user->registrations()->with('event')->where('end_date', '>', now());
$draftEvents = $user->events()->where('status','D')->paginate($pageLimit);
$publishedEvents = $user->events()->where('status','P')->paginate($pageLimit);
return view('users.index', compact('user', 'pastRegistrations','nextRegistrations', 'draftEvents', 'publishedEvents'));
}
}
The "dd($pastRegistrations);" shows:
HasMany {#257 ▼
#foreignKey: "registrations.main_participant_id"
#localKey: "id"
#query: Builder {#251 ▶}
#parent: User {#258 ▶}
#related: Registration {#254 ▶}
}
then to show the data:
<ul class="list-group" id="pastRegistration">
@foreach($pastRegistrations as $pastRegistration)
<li class="list-group-item">
<p class="font-size-sm"><i class="fa fa-calendar" aria-hidden="true"></i>
{{$pastRegistration->congress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{$pastRegistration->congress->name}}</h5>
<p class="font-size-sm"><i class="fa fa-ticket" aria-hidden="true"></i> Registration in {{$pastRegistration->created_at}}</p>
</li>
@endforeach
</ul>
You need to actually complete the queries:
$pastRegistrations = $user->registrations()->with('event')->where('end_date', '<', now())
->get();
$nextRegistrations = $user->registrations()->with('event')->where('end_date', '>', now())
->get();
Please or to participate in this conversation.