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

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

在 laravel 5 視圖中取消序列化一列數(shù)據(jù)的正確方法是什么

在 laravel 5 視圖中取消序列化一列數(shù)據(jù)的正確方法是什么

PHP
忽然笑 2022-08-05 15:52:23
我正在構(gòu)建一個(gè)應(yīng)用程序,其中有一列數(shù)據(jù),我正在序列化以存儲(chǔ)在數(shù)據(jù)庫中,因?yàn)槲艺也坏狡渌椒梢詫?shù)據(jù)存儲(chǔ)為一個(gè)對象。我的表單中數(shù)據(jù)是輸入復(fù)選框,如下所示。    <div class="form-group form-check col-sm-6">        </br>        <label for="careplan">Care Plan</label></br>        <input type ="checkbox" name="careplan[]" value="nursecallweekly">   Nurse call weekly</br>        <input type ="checkbox" name="careplan[]" value="nursecallbiweekly">   Nurse call bi-monthly</br>        <input type ="checkbox" name="careplan[]" value="nursecallmonthly">   Nurse call monthly</br>        <input type ="checkbox" name="careplan[]" value="weightcheckdaily">   Weight check daily</br>        <input type ="checkbox" name="careplan[]" value="weightcheckweekly">   Weight check weekly</br>        <input type ="checkbox" name="careplan[]" value="lowerextremity">   Lower extremity edema status</br>        <input type ="checkbox" name="careplan[]" value="dietaryreview">   Dietary review</br>        <input type ="checkbox" name="careplan[]" value="fluidintake">   Fluid intake review</br>        <input type ="checkbox" name="careplan[]" value="bloodpressure">   Blood pressure reading daily</br>        <input type ="checkbox" name="careplan[]" value="bloodpressureweekly">   Blood pressure reading weekly</br>        <input type ="checkbox" name="careplan[]" value="hypertensive">   Hypertensive symptoms check</br>        <input type ="checkbox" name="careplan[]" value="ptinrweekly">   PT/INR weekly review</br>    </div>護(hù)理計(jì)劃有多個(gè)項(xiàng)目可供選擇。我將它們分組到一個(gè)數(shù)組中,并使用序列化數(shù)組。    //Create new Patient information    $patient = new Patient;    $patient->first_name = $request->input('first_name');    $patient->last_name = $request->input('last_name');    $patient->dob = $request->input('dob');    $patient->contact_one = $request->input('contact_one');    $patient->contact_two = $request->input('contact_two');    $patient->care_giver_one = $request->input('care_giver_one');    $patient->care_giver_two = $request->input('care_giver_two');頂部的圖像是視圖。如您所見,將返回序列化數(shù)據(jù)。我已經(jīng)瀏覽了這個(gè)論壇,沒有一個(gè)發(fā)布的建議有效。
查看完整描述

1 回答

?
拉莫斯之舞

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

你應(yīng)該使用雄辯的突變體來做到這一點(diǎn)。


在數(shù)據(jù)庫上使用 JSON 列,讓我們稱之為 ,然后在模型中執(zhí)行:careplan


<?php


namespace App;


use Illuminate\Database\Eloquent\Model;


class Patient extends Model

{

    // ...


    protected $casts = [

        'careplan' => 'array',

    ];


    // ...

}

所以現(xiàn)在,你將使用一個(gè)元素,不再需要從數(shù)據(jù)庫中手動(dòng)序列化/取消序列化它。Laravel 將在存儲(chǔ)時(shí)將 轉(zhuǎn)換為 ,并將其轉(zhuǎn)換回從數(shù)據(jù)庫獲取值時(shí)。所以現(xiàn)在:arrayarrayjsonarray


$patient = new Patient;

$patient->first_name = $request->input('first_name');

// ...

$patient->careplan = $request->input('careplan'); // Laravel will convert it to json for you

$patient->save();

然后你會(huì)看到:


$patient = Patient::find(1);

dd($patient->careplan);

已轉(zhuǎn)換回 。array


查看完整回答
反對 回復(fù) 2022-08-05
  • 1 回答
  • 0 關(guān)注
  • 102 瀏覽

添加回答

舉報(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)