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

raffelustig's avatar

Don't know how status_human is used in Laravel

In our Laravel9 system for pistol competition we can list a table of competitions. If a competition will be open later then today for signups it will show: Anmälan öppnar 2022-06-15 as it does in Laravel 5.3. But in Laravel 9 it shows only: Anmälan öppnar. with no date. In the blade that shows this it looks like this:

<div class="table-responsive  hidden-xs" ng-if="competitions.competitions.total">
                    <table class="table table-hover table-bordered table-striped ">
                        <thead>
                            <tr>
                                <th>Datum</th>
                                <th>Tävling</th>
                                <th>Status</th>
                                <th>Mästerskap</th>
                                <th>Typ av tävling</th>
                                <th>Ort/stad</th>
                                <th>Vapengrupper</th>
                                <th>Anmäld</th>
                                <th>Anmälningar</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ui-sref="competition.show({id: competition.id, view: 'information'})" ng-repeat="competition in competitions.competitions.data">
                                <td class="text-nowrap"><% competition.date %></td>
                                <td><% competition.name %></td>




                                <td><% competition.status_human %></td> 

That statement is suppose to show something like this: https://imgur.com/MSBrS1g




                                <td><% (competition.championship.name) ? competition.championship.name : '-' %></td>
                                <td><% competition.competitiontype.name %></td>
                                <td><% competition.contact_city %></td>
                                <td><span ng-repeat="weapongroup in competition.weapongroups" class="label label-default margin-right-5 inline-block"><% weapongroup.name %></span></td>
                                <td>
                                    <span ng-repeat="weaponclass in competition.weaponclasses">
                                        <a ui-sref="signup({id: signup.id})" class="label label-primary margin-right-5" ng-repeat="signup in usersignups = (competition.usersignups | filter:{weaponclasses_id: weaponclass.id}: true)"><% (competition.championships_id) ? weaponclass.classname_general : weaponclass.classname %></a>
                                    </span>
                                </td>
                                <td class="text-right">
                                    <% competition.signups_count %>
                                </td>
                                <td><a ui-sref="competition.show({id: competition.id, view: 'information'})" class="btn btn-primary btn-xs">Visa</a></td>
                            </tr>
                        </tbody>
                    </table>
                </div>

In the competition Model we have this:

protected $appends = [
        'signups_count',
        'patrols_count',
        'teams_count',
        'stations_count',
        'results_count',
        'status',



        'status_human',



        'start_time_human',
        'final_time_human',
        'allow_signups_after_closing_date_human',
        'translations',
        'results_type_human',
        'available_logos',
        'pdf_logo_path',
        'pdf_logo_url',
    ];

and:

   public function getStatusHumanAttribute(){
        if($this->status == 'completed'):
            return _('Avslutad (genomförd)');
        elseif($this->status == 'stangd'):
            return _('Stängd');





        elseif($this->status == 'not_opened'):
            return _('Anmälan öppnar');





        elseif($this->status == 'closed'):
            return _('Anmälan stängd');
        elseif($this->status == 'after_signups_closing_date'):
            return _('Efteranmälan');
        else:
            return _('Öppen för anmälan');
        endif;
    }

So I wonder how this can be corrected to work in Laravel 9. I don't really know how this "status_human" works.

0 likes
17 replies
martinbean's avatar

I don't really know how this "status_human" works.

@raffelustig Neither do we. It’s something in your codebase. It’s nothing to do with Laravel.

1 like
vincent15000's avatar

Have you cheked in the localization file where translations are managed ?

raffelustig's avatar

Ok, understand. I have seen this in the Model:

    public function getStatusAttribute(){
        $status = 'open';
        $signupsCount = ($this->max_competitors) ? $this->Signups()->count() : 0;
        if($this->closed_at):
            $status = 'stangd'; 
        elseif($this->date < date('Y-m-d')):
            $status = 'completed';
        elseif((($this->max_competitors > 0 && $signupsCount >= $this->max_competitors) || $this->signups_closing_date < date('Y-m-d')) && !$this->allow_signups_after_closing_date):
            $status = 'closed';



        elseif($this->signups_opening_date > date('Y-m-d')):
            $status = 'not_opened';



        elseif(($this->max_competitors > 0 && $signupsCount >= $this->max_competitors) || ($this->signups_closing_date < date('Y-m-d') && $this->allow_signups_after_closing_date)):
            $status = 'after_signups_closing_date';
        endif;
        return $status;
    }

    public function getStatusHumanAttribute(){
        if($this->status == 'completed'):
            return _('Avslutad (genomförd)');
        elseif($this->status == 'stangd'):
            return _('Stängd');



        elseif($this->status == 'not_opened'):
            return _('Anmälan öppnar');



        elseif($this->status == 'closed'):
            return _('Anmälan stängd');
        elseif($this->status == 'after_signups_closing_date'):
            return _('Efteranmälan');
        else:
            return _('Öppen för anmälan');
        endif;
    }

So here: elseif($this->signups_opening_date > date('Y-m-d')): $status = 'not_opened';

"signups_opening_date" is the column in the competitions database table where th upcoming date is stored.

if opening date is larger then todays date we are getting status "not_opened" and this is giving us "'Anmälan öppnar" but where does the "signups_opening_date" come from that shall follow that? It should look like this: https://imgur.com/MSBrS1g

1 like
raffelustig's avatar

@vincent15000 Yes, but how do I get the date into the blade. It must have something to do with Laravel versions because it works in 5.3.

If I do this:

        <td><% competition.status_human %> <%competition.signups_opening_date%></td>

then I'm getting the date in there but the same date in all other states.

Is there a way of making a condition if when "status == 'not_opened'" is not set and then date won't show?

Tried this:

 @if (<%competition.signups_opening_date%> > now() )
                                <td><% competition.status_human %> <%competition.signups_opening_date%></td>
                                @else
                                <td><% competition.status_human %></td>
                                @endif

but doesn't work. It protest on < in @if (<%compe

1 like
vincent15000's avatar

@raffelustig As @snapey said, the date is probably added directly in the DOM by your JS framework (angular). So the answer is not in your Laravel code.

raffelustig's avatar

@vincent15000 yes, I realize that. Will look for Angular-js solution. But still if it works in Laravel 5.3 why not i 9? It's the very same code.

1 like
raffelustig's avatar

@vincent15000 In this code:

                        <tr ui-sref="competition.show({id: competition.id, view: 'information'})" ng-repeat="competition in competitions.competitions.data">
                                <td class="text-nowrap"><% competition.date %></td>
                                <td><% competition.name %></td>

                               
                                    <td><% competition.status_human %></td>
                                
                                <td><% (competition.championship.name) ? competition.championship.name : '-' %></td>

this: <% competition.status_human %> is presenting a text from a Model. Could it be possible to check what text there is coming and check it in an if-statement in the code above? In that case I could show the date like this: <% signups_opening_date %> after the text "Anmälan öppnar".

Snapey's avatar

Again, I assume this is something to do with Angular used in the original version of the site.

Not a Laravel issue

1 like
martinbean's avatar

@raffelustig I think you need to either get familiar with Laravel or Angular, or just hire someone, as I just feel as though I’ve seen dozens of questions from you now about this pistol competition app, and then posting here every time you hit a brick wall.

raffelustig's avatar
raffelustig
OP
Best Answer
Level 2

The problem is solved by this:

return _('Anmälan öppnar');

is changed to:

 return _("Anmälan öppnar $this->signups_opening_date");

So now it works fine. Thanks all for your help.

Snapey's avatar

@raffelustig Keep going this way, ultimately you will replace all angular code. Might as well have done that in the first place.

raffelustig's avatar

@Snapey Well, there are many thousands of angular code lines and it would take, for me, years to replace all that. So I will solve things step by step, so far it has worked. I have not any real problem in the system now, so it's a fully working system.

I'm now trying to make some improvements.

Please or to participate in this conversation.