gpt4 book ai didi

mysql - 如何在laravel中更新mysql的数据

转载 作者:行者123 更新时间:2023-11-29 15:42:35 24 4
gpt4 key购买 nike

我正在尝试使用表单中的值进行更新,并使用路由将其传递到更新 Controller 中,没有给出错误,但为什么更新数据后没有任何反应?

表格:

<form action="/update" id="frm_edit" method="post" enctype="multipart/form-data">

路线:

Route::post('/update', 'EditManga@update'); //update route
Route::post('/admin_page/manga_list', 'Add_Manga_Controller@upload')->name('upload.image');
Route::get('/admin_page/manga_list','ShowData@Manga_list');

Controller :

public function update(Request $request){
$this->validate($request, [
'image' => 'required|image|mimes:jpg,png,jpeg'
]);

//MENGAMBIL FILE IMAGE DARI FORM
$kode_manga = $request->input('kdmanga');
$judul = $request->input('jdmanga');
$alternatif = $request->input('almanga');
$author = $request->input('aumanga');
$status = $request->status;
$lastup = $request->input('lumanga');
$genre = $request->input('grmanga');
$lastc = $request->input('lcmanga');
$sinopsis = $request->input('sinopsis');
$file = $request->file('image');

DB::table('add_manga')->where('kode_manga',$kode_manga)->update([
'judul_manga' => $judul,
'alt_title' => $alternatif,
'author' => $author,
'status' => $status,
'uploaded' => $lastup,
'genre' => $genre,
'latest' => $lastc,
'summary' => $sinopsis
]);
return redirect('/admin_page/manga_list');
}
}

还有其他方法或者我的代码有问题吗?谢谢。

最佳答案

在您的场景中,这是另一个这样做的情况:

  public function update(Request $request, $id)
{


$this->validate($request, [
'image' => 'required|image|mimes:jpg,png,jpeg'
]);

//MENGAMBIL FILE IMAGE DARI FORM
$kode_manga = $request->input('kdmanga');

//getting the target row to updae
$addmanga = DB::table('add_manga')->select('*')
->where('kode_manga',$kode_manga)->get();

$id = $addmanga->id; // getting the id of the target

$add_manga = App\YOUR_MODEL_NAME::find($id);

$add_manga->judul_manga = $request->input('jdmanga');
$add_manga->alt_title = $request->input('almanga');
$add_manga->author = $request->input('aumanga');
$add_manga->status = $request->status;
$add_manga->uploaded = $request->input('lumanga');
$add_manga->genre = $request->input('grmanga');
$add_manga->latest = $request->input('lcmanga');
$add_manga->summary = $request->input('sinopsis');
$add_manga->file = $request->file('image');

$add_manga->save();

return redirect('/admin_page/manga_list');
}

希望这对您有用!

关于mysql - 如何在laravel中更新mysql的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57447310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com