Php 我怎样才能调用类似于laravel的forelse循环中的第一个结果(array_key_first)?
Php 我怎样才能调用类似于laravel的forelse循环中的第一个结果(array_key_first)?,php,laravel,Php,Laravel,@forelse($key=>$value形式的位置) 我希望显示单个位置/第一个位置,而不是所有位置 全视图代码 <div class="row"> <div class="col-sm-12"> @forelse($locations as $key => $value) <div class="box box-solid">
@forelse($key=>$value形式的位置)
我希望显示单个位置/第一个位置,而不是所有位置
全视图代码
<div class="row">
<div class="col-sm-12">
@forelse($locations as $key => $value)
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">@lang('sale.location'): {{$value}}</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-condensed table-bordered table-th-green text-center table-striped add_opening_stock_table">
<thead>
<tr>
<th>@lang( 'product.product_name' )</th>
<th>@lang( 'lang_v1.quantity_left' )</th>
<th>Unit Cost - تكلفة الوحدة)</th>
@if($enable_expiry == 1 && $product->enable_stock == 1)
<th>Exp. Date</th>
@endif
@if($enable_lot == 1)
<th>@lang( 'lang_v1.lot_number' )</th>
@endif
<th>Subtotal - المجموع الفرعي</th>
<th> </th>
</tr>
</thead>
<tbody>
@php
$subtotal = 0;
@endphp
@foreach($product->variations as $variation)
@if(empty($purchases[$key][$variation->id]))
@php
$purchases[$key][$variation->id][] = ['quantity' => 0,
'purchase_price' => $variation->default_purchase_price,
'purchase_line_id' => null,
'lot_number' => null
]
@endphp
@endif
@foreach($purchases[$key][$variation->id] as $sub_key => $var)
@php
$purchase_line_id = $var['purchase_line_id'];
$qty = $var['quantity'];
$purcahse_price = $var['purchase_price'];
$row_total = $qty * $purcahse_price;
$subtotal += $row_total;
$lot_number = $var['lot_number'];
@endphp
<tr>
<td>
{{ $product->name }} @if( $product->type == 'variable' ) (<b>{{ $variation->product_variation->name }}</b> : {{ $variation->name }}) @endif
@if(!empty($purchase_line_id))
{!! Form::hidden('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][purchase_line_id]', $purchase_line_id); !!}
@endif
</td>
<td>
<div class="input-group">
{!! Form::text('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][quantity]', @format_quantity($qty) , ['class' => 'form-control input-sm input_number purchase_quantity input_quantity', 'required']); !!}
<span class="input-group-addon">
{{ $product->unit->short_name }}
</span>
</div>
</td>
<td>
{!! Form::text('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][purchase_price]', @num_format($purcahse_price) , ['class' => 'form-control input-sm input_number unit_price', 'required']); !!}
</td>
@if($enable_expiry == 1 && $product->enable_stock == 1)
<td>
{!! Form::text('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][exp_date]', !empty($var['exp_date']) ? @format_date($var['exp_date']) : null , ['class' => 'form-control input-sm os_exp_date', 'readonly']); !!}
</td>
@endif
@if($enable_lot == 1)
<td>
{!! Form::text('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][lot_number]', $lot_number , ['class' => 'form-control input-sm']); !!}
</td>
@endif
<td>
<span class="row_subtotal_before_tax">{{@num_format($row_total)}}</span>
</td>
<td>
@if($loop->index == 0)
<button type="button" class="btn btn-primary btn-xs add_stock_row" data-sub-key="{{ count($purchases[$key][$variation->id])}}"
data-row-html='<tr>
<td>
{{ $product->name }} @if( $product->type == "variable" ) (<b>{{ $variation->product_variation->name }}</b> : {{ $variation->name }}) @endif
</td>
<td>
<div class="input-group">
<input class="form-control input-sm input_number purchase_quantity" required="" name="stocks[{{$key}}][{{$variation->id}}][__subkey__][quantity]" type="text" value="0">
<span class="input-group-addon">
{{ $product->unit->short_name }}
</span>
</div>
</td>
<td>
<input class="form-control input-sm input_number unit_price" required="" name="stocks[{{$key}}][{{$variation->id}}][__subkey__][purchase_price]" type="text" value="{{@num_format($purcahse_price)}}">
</td>
@if($enable_expiry == 1 && $product->enable_stock == 1)
<td>
<input class="form-control input-sm os_exp_date" required="" name="stocks[{{$key}}][{{$variation->id}}][__subkey__][exp_date]" type="text" readonly>
</td>
@endif
@if($enable_lot == 1)
<td>
<input class="form-control input-sm" name="stocks[{{$key}}][{{$variation->id}}][__subkey__][lot_number]" type="text">
</td>
@endif
<td>
<span class="row_subtotal_before_tax">
0.00
</span>
</td>
<td> </td></tr>'
><i class="fa fa-plus"></i></button>
@else
@endif
</td>
</tr>
@endforeach
@endforeach
</tbody>
<tfoot>
<tr>
<td colspan="@if($enable_expiry == 1 && $product->enable_stock == 1 && $enable_lot == 1) 5 @elseif(($enable_expiry == 1 && $product->enable_stock == 1) || $enable_lot == 1) @else 3 @endif"></td>
<td><strong>Total Amount - المبلغ الإجمالي: </strong> <span id="total_subtotal">{{@num_format($subtotal)}}</span>
<input type="hidden" id="total_subtotal_hidden" value=0>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div> <!--box end-->
@empty
<h3>@lang( 'lang_v1.product_not_assigned_to_any_location' )</h3>
@endforelse
</div>
</div>
@forelse($key=>$value的位置)
@lang('sale.location'):{{{$value}
@lang('product.product\u name')
@lang('lang\u v1.剩余数量')
单位成本(单位成本)
@如果($enable_expiration==1&&$product->enable_stock==1)
出口日期
@恩迪夫
@如果($enable_lot==1)
@lang(‘lang_v1.批号’)
@恩迪夫
小计
@php
$小计=0;
@endphp
@foreach($product->变更为$VARIANCE)
@if(空($purchases[$key][$variation->id]))
@php
$purchases[$key][$variation->id][]=['quantity'=>0,
“采购价格”=>$variation->默认采购价格,
“购买线id”=>空,
“批号”=>空
]
@endphp
@恩迪夫
@foreach($purchases[$key][$variation->id]作为$sub_key=>$var)
@php
$purchase_line_id=$var['purchase_line_id'];
$qty=$var['quantity'];
$purcahes_price=$var[‘采购价格’];
$row_总计=$qty*$PURCAHES_价格;
$subtotal+=$row\u total;
$lot_number=$var['lot_number'];
@endphp
{{$product->name}}@if($product->type=='variable')({{{$VARIANCE->product{U VARIANCE->name}}}:{{$VARIANCE->name}})@endif
@如果(!空($purchase\u line\u id))
{!!Form::hidden('stocks['.$key.]['.$variation->id.]['.$sub_key.].][purchase_line_id],$purchase_line_id)
@恩迪夫
{!!Form::text('stocks['.$key.]['.$variation->id.]['.$sub_key.].][quantity],@format_quantity($quantity),['class'=>'表单控制输入sm输入采购数量输入数量输入数量','required'])
{{$product->unit->short_name}
{!!Form::text('stocks['.$key.]['.$variation->id.]['.$sub_key.].][purchase_price],@num_format($purchase_price),['class'=>'表单控制输入sm输入编号单位价格','required'])
@如果($enable_expiration==1&&$product->enable_stock==1)
{!!Form::text('stocks['.$key.]['.$variation->id.]['.$sub_key.][exp_date]',!empty($var['exp_date'])?@format_date($var['exp_date]]:null,['class'=>'表单控件输入sm os_exp_date','readonly']
@恩迪夫
@如果($enable_lot==1)
{!!Form::text('stocks['.$key.]['.$variation->id.]['.$sub_key.][lot_number],$lot_number,['class'=>'表单控制输入sm'])
@恩迪夫
{{@num_格式($row_总计)}
@如果($loop->index==0)
@否则
@恩迪夫
@endforeach
@endforeach
总额-总额:{@num_格式($subtotal)}
@空的
@lang('lang\u v1.产品\u未\u分配给\u任何位置')
@endforelse
尝试使用@forelse($key=>$value)->first()$firstItem=$locations->first()
<div class="row">
<div class="col-sm-12">
@forelse($locations as $key => $value)
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">@lang('sale.location'): {{$value}}</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-condensed table-bordered table-th-green text-center table-striped add_opening_stock_table">
<thead>
<tr>
<th>@lang( 'product.product_name' )</th>
<th>@lang( 'lang_v1.quantity_left' )</th>
<th>Unit Cost - تكلفة الوحدة)</th>
@if($enable_expiry == 1 && $product->enable_stock == 1)
<th>Exp. Date</th>
@endif
@if($enable_lot == 1)
<th>@lang( 'lang_v1.lot_number' )</th>
@endif
<th>Subtotal - المجموع الفرعي</th>
<th> </th>
</tr>
</thead>
<tbody>
@php
$subtotal = 0;
@endphp
@foreach($product->variations as $variation)
@if(empty($purchases[$key][$variation->id]))
@php
$purchases[$key][$variation->id][] = ['quantity' => 0,
'purchase_price' => $variation->default_purchase_price,
'purchase_line_id' => null,
'lot_number' => null
]
@endphp
@endif
@foreach($purchases[$key][$variation->id] as $sub_key => $var)
@php
$purchase_line_id = $var['purchase_line_id'];
$qty = $var['quantity'];
$purcahse_price = $var['purchase_price'];
$row_total = $qty * $purcahse_price;
$subtotal += $row_total;
$lot_number = $var['lot_number'];
@endphp
<tr>
<td>
{{ $product->name }} @if( $product->type == 'variable' ) (<b>{{ $variation->product_variation->name }}</b> : {{ $variation->name }}) @endif
@if(!empty($purchase_line_id))
{!! Form::hidden('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][purchase_line_id]', $purchase_line_id); !!}
@endif
</td>
<td>
<div class="input-group">
{!! Form::text('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][quantity]', @format_quantity($qty) , ['class' => 'form-control input-sm input_number purchase_quantity input_quantity', 'required']); !!}
<span class="input-group-addon">
{{ $product->unit->short_name }}
</span>
</div>
</td>
<td>
{!! Form::text('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][purchase_price]', @num_format($purcahse_price) , ['class' => 'form-control input-sm input_number unit_price', 'required']); !!}
</td>
@if($enable_expiry == 1 && $product->enable_stock == 1)
<td>
{!! Form::text('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][exp_date]', !empty($var['exp_date']) ? @format_date($var['exp_date']) : null , ['class' => 'form-control input-sm os_exp_date', 'readonly']); !!}
</td>
@endif
@if($enable_lot == 1)
<td>
{!! Form::text('stocks[' . $key . '][' . $variation->id . '][' . $sub_key . '][lot_number]', $lot_number , ['class' => 'form-control input-sm']); !!}
</td>
@endif
<td>
<span class="row_subtotal_before_tax">{{@num_format($row_total)}}</span>
</td>
<td>
@if($loop->index == 0)
<button type="button" class="btn btn-primary btn-xs add_stock_row" data-sub-key="{{ count($purchases[$key][$variation->id])}}"
data-row-html='<tr>
<td>
{{ $product->name }} @if( $product->type == "variable" ) (<b>{{ $variation->product_variation->name }}</b> : {{ $variation->name }}) @endif
</td>
<td>
<div class="input-group">
<input class="form-control input-sm input_number purchase_quantity" required="" name="stocks[{{$key}}][{{$variation->id}}][__subkey__][quantity]" type="text" value="0">
<span class="input-group-addon">
{{ $product->unit->short_name }}
</span>
</div>
</td>
<td>
<input class="form-control input-sm input_number unit_price" required="" name="stocks[{{$key}}][{{$variation->id}}][__subkey__][purchase_price]" type="text" value="{{@num_format($purcahse_price)}}">
</td>
@if($enable_expiry == 1 && $product->enable_stock == 1)
<td>
<input class="form-control input-sm os_exp_date" required="" name="stocks[{{$key}}][{{$variation->id}}][__subkey__][exp_date]" type="text" readonly>
</td>
@endif
@if($enable_lot == 1)
<td>
<input class="form-control input-sm" name="stocks[{{$key}}][{{$variation->id}}][__subkey__][lot_number]" type="text">
</td>
@endif
<td>
<span class="row_subtotal_before_tax">
0.00
</span>
</td>
<td> </td></tr>'
><i class="fa fa-plus"></i></button>
@else
@endif
</td>
</tr>
@endforeach
@endforeach
</tbody>
<tfoot>
<tr>
<td colspan="@if($enable_expiry == 1 && $product->enable_stock == 1 && $enable_lot == 1) 5 @elseif(($enable_expiry == 1 && $product->enable_stock == 1) || $enable_lot == 1) @else 3 @endif"></td>
<td><strong>Total Amount - المبلغ الإجمالي: </strong> <span id="total_subtotal">{{@num_format($subtotal)}}</span>
<input type="hidden" id="total_subtotal_hidden" value=0>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div> <!--box end-->
@empty
<h3>@lang( 'lang_v1.product_not_assigned_to_any_location' )</h3>
@endforelse
</div>
</div>