Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adamjhn's avatar

How to achieve this context? (single query, multiple queries?)

I want to have a query using laravel that allows to get the details about a registration. I have this route:

Route::get('/conference/{id}/{slug?}/registration/{regID}/info', [
    'uses' => 'RegistrationController@getRegistrationInfo',
    'as'   =>'conferences.registrationInfo'
]);

When the user accesses this route I want to show the details of that specific registration of the user.

So, I want to have a query that allows to show for a specific registration, when the user clicks in the link associated with the above route "Route::get('/conference/{id}/{slug?}/registration/{regID}/info", show for each ticket/registration type associated with that registration id, in this case, were 2 registration types (2 participants), so a query that allows to show a list with two list items showing the registration info like:

<ul>
    <li>
        <span>show the registration ID here</span>
        <span>Conference name: conference name</span>
        <span>Conference date: 2018-06-13</span>
        <span>Registration type: general</span>
        <span> Participant: John W</span>
        <span>Price: 0<span>
    </li>
    <li>
        <span>show the registration ID here</span>
        <span>Conference name: conference name</span>
        <span>Conference date: 2018-06-13</span>
        <span>Registration type: plus</span>
        <span> Participant: Jake W</span>
        <span>Price: 1<span>
    </li>
<ul>

Do you know how this can be achieved? Im not understanding how to do this properly, if it should be only one query or multiple queries. Do you know how to properly achieve a query this context?

0 likes
3 replies
Cronix's avatar

Is there a reason why you need to pass 3 id's (including slug) to get the single registration? Aren't your registration id's unique?

This is a really bad route '/conference/{id}/{slug?}/registration/{regID}/info

First, slug can't be optional there. It must be included since it's in the middle of the route. If it wasn't included in the request, it would break because then "registration" would become the "slug", which is wrong.

Why can't it just be /registration/{regID}? You can get the conference via the inverse relationship of registration, so you probably don't need conference id at all, and I really see no use for slug in there.

1 like
adamjhn's avatar

Thanks, I had like that '/conference/{id}/{slug?}/registration/{regID}/info' because for the user should be more intuitive see that route to understand that he will get info about a registration of that specific conference. But maybe is not necessary. Maybe '/registration/{regID}/' with 'info' like '/registration/{regID}/info' is also intuitive.

In terms of the query(ies) to show the the list with list items, do you know if needs to be/should be only one query or multiple queries?

Cronix's avatar
Cronix
Best Answer
Level 67

Most users aren't even looking at the url. They don't care. They're not typing things directly into the url except the domain name to get to the site. They're looking at the links they're clicking on and what's presented on the page, so as long as that part is obvious to them and provides all of the info they need...

It would probably just be one query, assuming you have the proper relationships set up.

Registration::with('conference', 'registration_types.users')->find($registrationID);

That's not exactly it, but depends on how you have everything set up.

Get the registration by it's id, along with the conference it belongs to and the registration type with the users.

1 like

Please or to participate in this conversation.