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

raffelustig's avatar

What kind of database access is this <% something %>

In a laravel system 5.3 there are many blade with statements looking like this:

        <tr>
            <td>{{_('Time between %s', '<% competitions.competition.translations.patrols_name_plural %>')}}</td>
            <td>
                <div class="input-group">
                    <input type="tel" ng-model="competitions.competition.patrol_time_interval" class="form-control text-right" placeholder="{{_('Minutes')}}" aria-describedby="basic-addon2">
                    <span class="input-group-addon">{{_('minutes')}}</span>
                </div>
            </td>
        </tr>

The line containing <% comp... %> works fine in 5.3 but not in Laravel 7. They access database posts but how? How to make such lines work in v7?

0 likes
30 replies
vincent15000's avatar

I don't know this syntax, but it looks like you're trying to access to some language configuration file.

If that's effectively the case, perhaps you could try this.

__('competitions.competition.translations.patrols_name_plural')

Tell me if it helps.

MESSAGE UPDATED => it's not a Laravel code, but an Angular code.

raffelustig's avatar

@vincent15000 No, it refers to a column in competitions table in the database:

patrol_size (int, 8)
Kolumnpatrol_time (int, 10)
Kolumnpatrol_time_interval (int, 10)
Kolumnpatrol_time_rest (int, 10)
Kolumnpdf_logo (varchar, 'websh...)

in this case the time interval between patrols. In this case 10 minutes.

Snapey's avatar
Snapey
Best Answer
Level 122

@raffelustig unless you know angular you are going to struggle to modify this code

raffelustig's avatar

@Snapey Well, then I have to learn angular. Just wonder, is it angular I still need to use or any other code for Laravel 7?

raffelustig's avatar

@vincent15000 Yes, in fact it takes a name from app/Models/Competition.php:

       else:
            $translations->patrols_name_singular = _('patrull');
            $translations->patrols_name_plural = _('patruller');
            $translations->patrols_list_singular = _('patrullista');
Sinnbeck's avatar

@raffelustig can you show the complete code there?

Also laravel has nothing to do with angular. Angular is a frontend framework. So you can use it if you want

Sinnbeck's avatar

It does not look like laravel (at least not 5.3). It kinda looks like twig though (not 100%). Maybe a package?

How do you know it does database queries? And what is the output?

vincent15000's avatar

@raffelustig Are you sure it's a Laravel code ? It looks like it's rather an Angular code, isn't it ? ng-model is Angular code.

raffelustig's avatar

@jlrdw Ok, fine. Now, these statements works fine in the laravel 5.3 version but in laravel 7 I'm getting "expects exactly 1 parameter, 2 given" for every single of these. If I remove the first, it errors the second and so on. How to adapt these in vers. 7?

raffelustig's avatar

I have a similar case here:

            <tr>
                <td colspan="6">
                    <button class="btn btn-primary" ng-click="stations.createStation();">{{_('Create %s', '<% competitions.competition.translations.stations_name_singular %>')}}</button>
                </td>
            </tr>

Here I got the error "expects exactly 1 parameter, 2 given" --BUT-- if I remove the <%...%> part:

<tr>
                <td colspan="6">
                    <button class="btn btn-primary" ng-click="stations.createStation();">{{_('Create %s')}}</button>
                </td>
            </tr>

it works and creates a station in the database every time I click "Create". But the button does not show "Create station", only "Create %" The "station" should be taken from app/Models/Competition.php here:

            $translations->stations_name_singular = _('station');
            $translations->stations_name_plural = _('stations');
Snapey's avatar

angular is a javascript framework and runs in the browser

your blade echo

<button class="btn btn-primary" ng-click="stations.createStation();">{{_('Create %s', '<% competitions.competition.translations.stations_name_singular %>')}}</button>

should output virtually the same string if there is no localisation translation

<button class="btn btn-primary" ng-click="stations.createStation();">Create <% competitions.competition.translations.stations_name_singular %></button>

then angular will replace the <%....%> part at runtime

raffelustig's avatar

@Snapey will try that. And yes! it really worked, and I got the "Create station" exactly as it should be! I will try this on other statementes and se what it does there. So those {{_( are making the problems?

Snapey's avatar

@raffelustig I've not given you anything to try !

I assumed that these were standard translation strings, but they would be double underscore {{__('string')}} but you seem to have single underscore function name.

Check if you have a helpers file...

%s is a placeholder typically used with sprintf() function and allows replacement in the middle of strings, eg

sprintf('Mr %s will see you now for your % appointment','snapey','10:00')

The example you are working with here is a simple concatenation of two strings so you can just smash them together, but you may have other places in the code that are more complex. You need to find and fix that helper.

raffelustig's avatar

@Snapey Well, in config I have laravel-gettext.php and in there there is:

   /**
     * The adapter used to sync the laravel built-in locale
     */
    'adapter' => \Xinax\LaravelGettext\Adapters\LaravelAdapter::class,

    /**
     * Use custom locale that is not supported by the system
     */
    'custom-locale' => false,

    /**
     * The keywords list used by poedit to search the strings to be translated
     *
     * The "_", "__" and "gettext" are singular translation functions
     * The "_n" and "ngettext" are plural translation functions
     * The "dgettext" function allows a translation domain to be explicitly specified
     *
     * "__" and "_n" are helpers functions @see \Xinax\LaravelGettext\Support\helpers.php
     */
 'keywords-list' => ['_', '__', 'gettext', '_n:1,2', 'ngettext:1,2', 'dgettext:2'],
];
raffelustig's avatar

@Sinnbeck Yes, from the very beginning. The thing is that this system is not written by me, but were trying to upgrade it from 5.3 to at least 7

raffelustig's avatar

@Snapey yes, I remember that we had sprintf but took those away because of some problems I don't recall. Do you think that sprintf should be put in again (laravel 7)?

raffelustig's avatar

@Snapey @Snapey Well, I have used your idea to remove >{{_('. , ', ' and )}} in make stations blade and it works perfect. The blade shows exactly what's expected and stations are stored in database. Now I did the same in the blade patrols. There were about 20-25 different statements that I adjusted like that. Finally I got another error:

[2022-01-15 15:38:02] local.ERROR: Target [App\Contracts\ExcelInterface] is not instantiable while building 

but realized that I have missed to reinstall "maatwebsite/excel": "^3.1.35", When I installed that It works fine now.

Snapey's avatar

That package is abandoned so I don't know how you upgraded to Laravel 7 without composer complaining.

Everywhere {{_( is found, you need to rewrite. I would first search and find out how many that might be

vincent15000's avatar

I'd like to see your controller ... According to me, the problem is in your controller. I think that your front (with Angular) sends informations to your back (Laravel).

raffelustig's avatar

I'm going to close this now as we have a guy made the system run in Laravel 8. Thanks all for your efforts and help.

Sinnbeck's avatar

@raffelustig That is the best answer? Not one of the answers that actually told you what that syntax meant?

Please or to participate in this conversation.