第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Laravel 在 1 個(gè)標(biāo)題下顯示同一日期的所有職位

Laravel 在 1 個(gè)標(biāo)題下顯示同一日期的所有職位

PHP
狐的傳說 2023-07-07 10:42:41
我創(chuàng)建了一個(gè)表格,將日期顯示為標(biāo)題,然后在其下方顯示當(dāng)天的工作。但是,當(dāng)我在同一天有兩項(xiàng)工作時(shí),它會(huì)在每項(xiàng)工作下方顯示兩次日期。我想在 1 個(gè)日期(標(biāo)題)下一起顯示當(dāng)天的所有作業(yè)。<table>? ? <tbody>? ? ? ? @foreach($loads as $load)? ? ? ? ? ? <tr><td? colspan="8" class="ml-1 h4 text-warning">{{date('l, d-F-Y', strtotime($load->pickup_date))}}</td></tr>? ? ? ? ? ? <tr>? ? ? ? ? ? ? ? <td>{{date("g:i a", strtotime($load->pick_up_time))}}</td>? ? ? ? ? ? ? ? <td><textarea>{{$user->customer}}</textarea></td>? ? ? ? ? ? ? ? <td>{{$load->pickup_location}}</td>? ? ? ? ? ? ? ? <td>{{$load->drop_off_location}}</td>? ? ? ? ? ? ? ?<!-- <td>{{$load->distance}}</td>-->? ? ? ? ? ? ? ? <!--<td><textarea>{{$load->description}}</textarea></td>-->? ? ? ? ? ? ? ? <!--<td>{{$load->customer_reference}}</td>-->? ? ? ? ? ? ? ? <td>{{$load->vehicle}}</td>? ? ? ? ? ? ? ? <td>{{$load->driver}}</td>? ? ? ? ? ? ? ? <td><textarea>{{$load->notes}}</textarea></td>? ? ? ? ? ? ? ? <td>? ? ? ? ? ? ? ? ? ? <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-pencil-square-o" style="color:#FF6F00;"></i></a>? ? ? ? ? ? ? ? ? ? <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-truck" style="color:#5cac00;"></i></a>? ? ? ? ? ? ? ? ? ? <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-phone" style="color:#00b1e6;"></i></a></td>? ? ? ? ? ? ? ? </td>? ? ? ? ? ? </tr>? ? ? ? @endforeach? ? </tbody></table>
查看完整描述

3 回答

?
ITMISS

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊

在控制器中:


? ? public function store(Request $request) {




? ? $originalDate = $request['pickup'];

? ? $PickUpDate = date("Y-m-d", strtotime($originalDate));


? ? $originalDate = $request['destination'];

? ? $DestinationDate = date("Y-m-d", strtotime($originalDate));

? ??

? ? ?$originalDate = $request['createdDate'];

? ? $createdDate = date("Y-m-d", strtotime($originalDate));


? ? $load = new Load;


? ? $load->user_id = Auth::id();

? ? $load->customer = $request['customer'];

? ? $load->pickup_date = $PickUpDate;

? ? $load->destination_date = $DestinationDate;

? ? $load->creation_date = $createdDate;

? ? $load->trailer = $request->trailer;

? ? $load->pickup_location = $request['pickup_location'];

? ? $load->drop_off_location = $request['drop_off_location'];

? ? $load->distance = $request['distance'];

? ? $load->description = $request['description'];

? ? $load->quantity = 1;

? ? $load->customer_reference = $request['customer_reference'];

? ? $load->load_number = $request['load_number'];

? ? $load->additional_details = $request['additional_details'];

? ? $load->vehicle = $request['vehicle'];

? ? $load->driver = $request['driver'];

? ? $load->notes = $request['notes'];

? ? $load->Rate = $request['rate'];

? ? $load->pick_up_time = $request['pickupTime'];

? ? $load->destination_time = $request['destinationTime'];

? ? ?$load->creation_time = $request['createdTime'];

? ? $load->consignee = $request['consignee'];

? ? $load->save();


? ? return back()->with('Success', 'Load created successfully');

}? ??

在刀片中:


? ? ?<tbody> dd($loads);

? ? ? ? ? ? ? ? ? ? ? @foreach($loads as $key=>$new_load)?


? ? ? ? ? ? ? ? ? ? ? ? <tr><td? colspan="8" class="ml-1 h4 text-warning">{{date('l, d-F-Y', strtotime($key))}}</td></tr>

? ? ? ? ? ??

? ? ? ? ? ? ? ? ? ? ? ? ?@foreach($new_load as $load)

? ? ? ? ? ? ? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>{{date("g:i a", strtotime($load->pick_up_time))}}</td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>{{$load->customer}}</td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>{{$load->pickup_location}}</td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>{{$load->drop_off_location}}</td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<!-- <td>{{$load->distance}}</td>-->

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <!--<td><textarea>{{$load->description}}</textarea></td>-->

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <!--<td>{{$load->customer_reference}}</td>-->

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>{{$load->vehicle}}</td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<!-- <td>{{$load->trailer}}</td>-->

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>{{$load->driver}}</td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td><textarea>{{$load->notes}}</textarea></td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-pencil-square-o" style="color:#FF6F00;"></i></a>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-truck" style="color:#5cac00;"></i></a>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-phone" style="color:#00b1e6;"></i></a></td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? ? ? ? ? ? ? </tr>

??


? ? ? ? ? ? ? ? ? ? ? ? @endforeach

? ? ? ? ? ? ? ? ? ? @endforeach

? ? ? ? ? ? ?</tbody>


查看完整回答
反對(duì) 回復(fù) 2023-07-07
?
BIG陽

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

最好的方法是首先對(duì)您的集合進(jìn)行排序,以確保每個(gè)日期都有自己的負(fù)載:


$loads = {....}; // here are the loads

$dates = []; // here will be the dates


// get all loads pickup dates

$dates = $loads->pluck('pickup_date');


// remove duplicated dates

$dates = $dates->unique();


// assign each load to its date

foreach($dates->toArray() as $key => $date)

    $dates[$date] = $loads->filter(function($load){

        return $load->pickup_date === $date;

    });


// return the dates instead of loads

return $dates;

現(xiàn)在來說說刀片部分:


<table>

    <tbody>

        @foreach($dates as $date => $collection)

            <tr>

                <td  colspan="8" class="ml-1 h4 text-warning">{{date('l, d-F-Y', strtotime($date))}}</td>

            </tr>

            @foreach($collection as $load)

                <tr>

                    <td>{{date("g:i a", strtotime($load->pick_up_time))}}</td>

                    <td><textarea>{{$user->customer}}</textarea></td>

                    <td>{{$load->pickup_location}}</td>

                    <td>{{$load->drop_off_location}}</td>

                   <!-- <td>{{$load->distance}}</td>-->

                    <!--<td><textarea>{{$load->description}}</textarea></td>-->

                    <!--<td>{{$load->customer_reference}}</td>-->

                    <td>{{$load->vehicle}}</td>

                    <td>{{$load->driver}}</td>

                    <td><textarea>{{$load->notes}}</textarea></td>

                    <td>

                        <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-pencil-square-o" style="color:#FF6F00;"></i></a>

                        <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-truck" style="color:#5cac00;"></i></a>

                        <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-phone" style="color:#00b1e6;"></i></a></td>

                    </td>

                </tr>

            @endforeach

        @endforeach

    </tbody>

</table>


查看完整回答
反對(duì) 回復(fù) 2023-07-07
?
揚(yáng)帆大魚

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊

我建議將日期保存在循環(huán)內(nèi),然后在渲染標(biāo)題之前檢查它是否與上一個(gè)相同;我不熟悉 Laravel,正在尋找一種方法來做到這一點(diǎn),但看起來顯然不鼓勵(lì)在模板本身中設(shè)置局部變量。


您需要做的基本上是按日期(或者在本例中,按標(biāo)題)對(duì)結(jié)果進(jìn)行分組,這樣當(dāng)您遍歷循環(huán)時(shí),您可以在同一日期擁有多行。


這是一個(gè)非常粗略的示例,但應(yīng)該可以讓您更好地了解我的建議:


$loads = array(

    array( 'pickup_date' => 'foo', /* more items here... */ ),

    array( 'pickup_date' => 'foo', /* more items here... */ ),

    array( 'pickup_date' => 'bar', /* more items here... */ ),

    array( 'pickup_date' => 'bar', /* more items here... */ ),

    array( 'pickup_date' => 'baz', /* more items here... */ ),

);


// Group by date...

$grouped_loads = array_reduce($loads, function($carry, $load) {

    $carry[ $load['pickup_date'] ][]= $load;

    

    return $carry;

}, array());

此時(shí),$grouped_loads應(yīng)該如下所示:


array(

    'foo' => array(

        array( 'pickup_date' => 'foo', /* more items here... */ ),

        array( 'pickup_date' => 'foo', /* more items here... */ ),

    ),

    'bar' => array(

        array( 'pickup_date' => 'bar', /* more items here... */ ),

        array( 'pickup_date' => 'bar', /* more items here... */ ),

    ),

    'baz' => array(

        array( 'pickup_date' => 'baz', /* more items here... */ ),

    ),

);

因此,您現(xiàn)在將執(zhí)行一個(gè)嵌套操作foreach,每個(gè)日期一個(gè),然后日期中的每個(gè)項(xiàng)目一個(gè)。Laravel 為您提供了 和$loop,$loop->first因此您現(xiàn)在只能渲染第一項(xiàng)的標(biāo)題:


@foreach($grouped_loads as $loads)

    @foreach($loads as $load)

        @if ($loop->first)

        <tr>

            <td  colspan="8" class="ml-1 h4 text-warning">

                {{date('l, d-F-Y', strtotime($load->pickup_date))}}

            </td>

        </tr>

        @endif

        <tr>

            <td>{{date("g:i a", strtotime($load->pick_up_time))}}</td>

            <td><textarea>{{$user->customer}}</textarea></td>

            <td>{{$load->pickup_location}}</td>

            <td>{{$load->drop_off_location}}</td>

            <!-- <td>{{$load->distance}}</td>-->

            <!--<td><textarea>{{$load->description}}</textarea></td>-->

            <!--<td>{{$load->customer_reference}}</td>-->

            <td>{{$load->vehicle}}</td>

            <td>{{$load->driver}}</td>

            <td><textarea>{{$load->notes}}</textarea></td>

            <td>

                <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-pencil-square-o" style="color:#FF6F00;"></i></a>

                <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-truck" style="color:#5cac00;"></i></a>

                <a href="{{route('EditLoad',$load->id)}}" class="fa fa-2x fa-phone" style="color:#00b1e6;"></i></a>

            </td>

        </tr>

    @endforeach

@endforeach


查看完整回答
反對(duì) 回復(fù) 2023-07-07
  • 3 回答
  • 0 關(guān)注
  • 159 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)