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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在laravel中以單一形式處理多個輸入?

如何在laravel中以單一形式處理多個輸入?

慕桂英546537 2021-06-28 13:56:52
我有一個表格,我要求用戶標記他們的出席情況,我發(fā)送Carbon::now()作為默認和隱藏輸入,每當用戶點擊按鈕時,它應(yīng)該存儲在數(shù)據(jù)庫中,但問題是我有四個這樣的字段,每當我點擊提交按鈕它存儲所有字段的值。我對這件事很陌生,請幫助我。我也包括代碼??捶ǎ?lt;div class="card" style="max-width: 600px; margin:auto; margin-bottom:50px;margin-top:40px;">    <div class="card-header" style="text-align:center">        Today: @php $today = \Carbon\Carbon::now()->format('d-m-Y'); @endphp &nbsp; {{$today}}    </div>    <form action="{{ route('timesheet.store') }}" method="POST">        @csrf    <div class="card-body">        @php            $now = \carbon\Carbon::now();        @endphp        <ul class="list-group">            <li class="list-group-item">                <label for="in_time">Day start</label>                <input name="in_time" type="datetime" style="display:none" value="{{$now}}">                <span style="float:right"><button type="submit" class="btn btn-success btn-sm">Mark</button></span>            </li>            <li class="list-group-item">                <label for="break_out">Break-out</label>                <input name="break_out" type="datetime" style="display:none" value="{{$now}}">                <span style="float:right"><button type="submit" class="btn btn-success btn-sm">Mark</button></span>            </li>我必須做的是:當用戶點擊“標記”按鈕時,該特定字段的值和其余字段應(yīng)該與空值一起存儲,因為所有列都可以為空。一旦用戶點擊按鈕并且值成功存儲在數(shù)據(jù)庫中,按鈕應(yīng)替換為刻度線按鈕,并應(yīng)禁用到第二天,即午夜。任何幫助將不勝感激。抱歉,由于未使用堆棧溢出,因此問題格式錯誤。
查看完整描述

2 回答

?
波斯汪

TA貢獻1811條經(jīng)驗 獲得超4個贊

請試試這個,


public function store(Request $request)

{

    Timesheet::create([

        'in_time' => $request->get('in_time'),

        'out_time' => $request->get('out_time'),

        'break_out' => $request->get('break_out'),

        'break_in' => $request->get('break_in'),

        'user_id' => \Auth::user()->id,

    ]);



    return redirect()->route('timesheet.create')

        ->with('success', 'Attendance marked successfully.');

}


查看完整回答
反對 回復 2021-07-08
?
冉冉說

TA貢獻1877條經(jīng)驗 獲得超1個贊

這聽起來像是 AJAX 的工作。


步驟1:


為所有按鈕添加通用類


// new time-btn class

<span style="float:right"><button type="submit" class="btn btn-success btn-sm 

btn time-btn">Mark</button></span>

第2步:


獲取數(shù)據(jù)并使用 AJAX 發(fā)送(使用 jquery):


$(document).on('click', '.time-btn', function(e) {

   e.preventDefault();


   // get value of first input before the button

   var time = $(this).prev('input').val();

   // get input name

   var name = $(this).prev('input').attr('name')


   // validate time if necessary


     $.ajax({

        url: '/time/store', // insert route url here

        type: 'POST',

        data: {time: time, name: name},

        success: function( response ) {

            response = JSON.parse( response );

           // add tick mark to button here

        },

        error: function (xhr, status, error) {

            console.log( xhr.responseText );

        }

     });

  });

第 3 步:


更新控制器


public function store(Request $request)

{   


Timesheet::create([

    'in_time' => request('name') == 'in_time' ? request('time') : null,

    'out_time' => request('name') == 'out_time' ? request('time') : null,

    // do the same for tother

    ...

    'user_id' => Auth::user()->id,

]);



return redirect()->route('timesheet.create')

    ->with('success', 'Attendance marked successfully.');

}


查看完整回答
反對 回復 2021-07-08
  • 2 回答
  • 0 關(guān)注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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