如何在 Laravel 9 中將 json 資料和表單資料發佈到單一請求中
P粉083785014
P粉083785014 2024-01-02 14:44:22
0
1
461

我有一個表單,在表單內我可以輸入多個圖像,並將其轉換為 json

我的表單 html create.blade.php

<form method="post" action="{{ route('m_announcement.store') }}" enctype="multipart/form-data">
                @csrf
/////// many input just not included 
//////// my image input
                 <div class="row mb-4">
                    <label class="col-sm-2 col-label-form">Upload Images</label>
                    <div class="col-sm-10">
                        <input type="file" name="files[]" id="files" multiple
                            accept="image/jpeg, image/png, image/gif," onchange="timeFunction()"><br />
                    </div>
                </div>

///////// my imagae preview
                <output id="Filelist"></output>

                <div class="text-center">
                    <input type="submit" class="btn btn-primary" value="Add" />
                </div>

</form>

腳本中的此函數以 json 格式將映像輸出到 var AttachmentArray,我也想透過表單發布

function printvalues() {
            console.log(AttachmentArray); all image converted in base64 output in json format with imahe details

有沒有辦法將 json 連接到表單,當我按提交 json 時,資料將根據請求輸出

laravel 9 公告控制器.php

#
public function store(Request $request)
    {
      
        //dd($request);
        $jsonimages = $request->jsonimages;

      // decode the json a create loop to upload to database image
      // some code to upload the form to announcement database

        //image upload
}

我不只是在前端,大多數時候我首先在後端開發,這是我的第一個網頁應用程式項目,我嘗試搜尋ajax或其他東西,但我還不明白。

P粉083785014
P粉083785014

全部回覆(1)
P粉518799557

您可以使用以下方式取得欄位輸入的名稱

dd($request->file->('files'));

請參閱此處以了解更多資訊在 laravel 9 中檢索上傳的檔案一个>

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!