php - Make a function containing blade syntax -


i have blade in view. right now, have 6 blocks of them in view because i'm not sure how refactor it.

<div class="row filemanager"> <div class="col-sm-12">   @foreach ($devices $device)       @if( $device->vlan_id == 100 , $device->device_activity == 'active' )         <div class="col-xs-6 col-sm-4 col-md-2 text-center">           <div class="thmb">             <div class="btn-group fm-group" style="display: none;">                 <button type="button" class="btn btn-default dropdown-toggle fm-toggle" data-toggle="dropdown">                   <span class="caret"></span>                 </button>                 <ul class="dropdown-menu fm-menu" role="menu">                   <li id="device-menu">                   <a class="changedevicenamebtn" href="#"><i class="fa fa-pencil"></i> change device name </a>                   </li>                 </ul>             </div>             <div class="thmb-prev">               <a href="/{{$cpe_mac}}/device/{{$device->device_mac}}">                @if(isset($device->device_name))                {{-- show base on device name --}}               <img src="/images/photos/devices/{{img($device->device_name)}}.jpg" class="draggable img-responsive" alt="">                @else                    {{-- no device name set --}}                   @if($device->hostname != '')                      {{-- show base on hostname --}}                     <img src="/images/photos/devices/{{img($device->hostname)}}.jpg" class="draggable img-responsive" alt="">                    @else                      {{-- show default --}}                     <img src="/images/photos/devices/no-img.jpg" class="draggable img-responsive" alt="">                    @endif                 @endif                </a>             </div>             <h5 class="fm-title device_name">               <a href="/{{$cpe_mac}}/device/{{$device->device_mac}}">               @if($device->hostname == '')               no devicename               @else               {{ $device->hostname}}               @endif                </a>             </h5>             <h5 class="text-muted device_ip">{{$device->ip_address}}</h5>             <h5 class="text-muted device_mac">{{$device->device_mac}}</h5>                <?php                   $status = ucfirst(strtolower($device->device_activity));                   if ($status == 'active'){                       $color = '#1caf9a';                   }else{                       $color = '#d9534f';                   }               ?>                <h5>{{ $status }}                 <i class="fa fa-circle" style="color:{{$color}}; margin-left: 7px;"></i>               </h5>             </div>         </div>          @endif       @endforeach  </div> </div> 

i want make function containing blade, , replace

$device->vlan_id, , $device->device_activity.

example,

public static devicerow(100,active){  ... blade ...   } 

now, function 6 times, rather duplicate block of code 6 times.

is possible ?

any hints / suggestions on appreciated !

you can make partial blade , send variable parameter:

in parent view this:

@foreach($somelist $item)   @include('view.partial', ['name' => $item->name]) @endforeach 

and in file called partial.blade.php, this:

{{ $device->$name }} 

it's main idea. tell me if helps...


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -