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

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

無法編輯數(shù)據(jù)庫,Laravel

無法編輯數(shù)據(jù)庫,Laravel

PHP
紅顏莎娜 2023-08-11 16:46:18
我有一個帶有文本字段和圖像字段的編輯表單,用戶可以根據(jù)需要編輯和上傳新文本或圖像。但如果用戶不上傳新圖像,我只想將舊圖像保留在數(shù)據(jù)庫中。我的問題問題是,當(dāng)我點擊上傳按鈕時,我被重定向到文章頁面,并且沒有顯示錯誤,但數(shù)據(jù)庫尚未更新。任何幫助將不勝感激,因為我嘗試了多種方法但沒有成功。先感謝您。網(wǎng)頁.phpRoute::get('/tests/edit/{id}', 'TestController@edit');Route::patch('/tests', 'TestController@update');測試控制器.phppublic function edit(Request $request){     $test = Test::findOrFail($request->id);    return view('test.edit', ['test' => $test]);}public function update(Request $request, Test $test){    $test->user_id = $request->user()->id;    $test->name = $request->name;    if($request->hasFile('image')) {        Storage::delete('public/image/' . $test->image); //Delete old image        $path = $request->file('image')->store('public/image');        $test->image = basename($path);    }        $test->update();    return redirect('/tests')}編輯.blade.php@extends('layouts.app')@section('content')<div>    <form action="/tests" method="post" enctype="multipart/form-data">        {{ csrf_field() }}        {{ method_field('patch') }}            name:<input type="text" name="name" value='{{ $test->name }}'><br>            image: <input type="file" name="image"><br>            <input type='submit' value='upload'>    </form></div>@endsection
查看完整描述

2 回答

?
肥皂起泡泡

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

edit.blade.php 添加以下內(nèi)容:

  <input type="hidden" name="id" value="{{ $test->id }}">

測試控制器.php

 use $test->save(); instead of $test->update();


查看完整回答
反對 回復(fù) 2023-08-11
?
青春有我

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

我和你有同樣的問題。我在一個使用 laravel 的訂購網(wǎng)站上工作,你可以從 laravel 獲取數(shù)據(jù)并將其顯示給用戶,他也可以從網(wǎng)站訂購一些東西,數(shù)據(jù)庫將被更新。但是,我也無法得到或更新數(shù)據(jù)庫中的數(shù)據(jù)。我使用 wampserver、mysql,一旦我在 phpmyadmin 中切換到 MariaDB 而不是 mysql,問題就解決了:http://localhost/phpmyadmin/



查看完整回答
反對 回復(fù) 2023-08-11
  • 2 回答
  • 0 關(guān)注
  • 151 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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