亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

無法編輯數據庫,Laravel

無法編輯數據庫,Laravel

PHP
紅顏莎娜 2023-08-11 16:46:18
我有一個帶有文本字段和圖像字段的編輯表單,用戶可以根據需要編輯和上傳新文本或圖像。但如果用戶不上傳新圖像,我只想將舊圖像保留在數據庫中。我的問題問題是,當我點擊上傳按鈕時,我被重定向到文章頁面,并且沒有顯示錯誤,但數據庫尚未更新。任何幫助將不勝感激,因為我嘗試了多種方法但沒有成功。先感謝您。網頁.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條經驗 獲得超6個贊

edit.blade.php 添加以下內容:

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

測試控制器.php

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


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

TA貢獻1784條經驗 獲得超8個贊

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



查看完整回答
反對 回復 2023-08-11
  • 2 回答
  • 0 關注
  • 154 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號