-1
        @foreach ($modules as $module)

                @if ($module->name === "h_car_positions")   $module_name == "history_car_positions";    @endif


            <tr>
                <td>{{ $module->id }}</td>
                <td><a href="{{ url(config('laraadmin.adminRoute') . '/modules/'.$module->id) }}">{{ $module->name }}</a></td>
                <td>{{ $module->name_db }}</td>

                <td>{{ Module::itemCount( $module_name ) }}</td>
                <td>
                    <a href="{{ url(config('laraadmin.adminRoute') . '/modules/'.$module->id)}}#fields" class="btn btn-primary btn-xs" style="display:inline;padding:2px 5px 3px 5px;"><i class="fa fa-edit"></i></a>
                    <a href="{{ url(config('laraadmin.adminRoute') . '/modules/'.$module->id)}}#access" class="btn btn-warning btn-xs" style="display:inline;padding:2px 5px 3px 5px;"><i class="fa fa-key"></i></a>
                    <a href="{{ url(config('laraadmin.adminRoute') . '/modules/'.$module->id)}}#sort" class="btn btn-success btn-xs" style="display:inline;padding:2px 5px 3px 5px;"><i class="fa fa-sort"></i></a>
                    <a module_name="{{ $module->name }}" module_id="{{ $module->id }}" class="btn btn-danger btn-xs delete_module" style="display:inline;padding:2px 5px 3px 5px;"><i class="fa fa-trash"></i></a>
                </td>
            </tr>
        @endforeach

i want to assign history_car_positions to $module name when the if statment is true how to do that in blade

3 Answers3

1

I should first note that your syntax is incorrect - you're comparing (==), not assigning (=).

But Blade, being an interpreter, has its own control structure for raw PHP.

However, if you're simply passing this variable into itemCount, you may want to evaluate and assign this in your view, rather than directly in the template. It'll be much cleaner for you to maintain.

Morgon
  • 3,269
  • 1
  • 27
  • 32
  • i'm very new to blade .i'm editing in the view and thats the for each for displaying the data i just want to change the value of the name when it's == the condition in the if statment – mohamed mohamed Apr 16 '19 at 17:41
  • the proplem is how to pass the php variable to {{ Module::itemCount( $module_name ) }} – mohamed mohamed Apr 16 '19 at 17:58
  • If `itemCount` doesn't properly read your `$module_name` variable, then this is the other reason why assigning that variable in your view would be helpful. As for access to your class, you'll need to either call it from its FQCN (`App\Module`, etc) or create an alias. See https://laracasts.com/discuss/channels/general-discussion/how-to-call-a-static-method-inside-a-blade-in-laravel-5 – Morgon Apr 17 '19 at 04:39
0

You could try the php directive laravel docs

@if ($module->name === "h_car_positions")
   @php
      $module_name = "history_car_positions"; // use = instead of ==
   @endphp
@endif
Ramy Herrira
  • 574
  • 10
  • 13
  • when i try : {{ Module::itemCount(@php $module_name @endphp) }} i get syntax error, unexpected '<' and when i try that : {{ Module::itemCount( $module_name ) }} i get undefined variable $module_name – mohamed mohamed Apr 16 '19 at 17:35
  • You got 'undefined variable ...' message because `$module_name` is only defined when `$module->name === "h_car_positions"`. Just define it beforehand or add an else statement. – Ramy Herrira Apr 16 '19 at 17:42
  • even when i made the else statment i got same error the proplem is how to pass the php variable to {{ Module::itemCount( $module_name ) }} – mohamed mohamed Apr 16 '19 at 17:58
0

Use php tags

@if ($module->name === "h_car_positions")  <?php $module_name = "history_car_positions"; ?> @endif
Arleigh Hix
  • 9,990
  • 1
  • 14
  • 31