Laravel插入4张图片触发QueryException错误求助
2026-6-25
问题描述
#
使用WAMP服务器搭配Laravel框架开发,表单包含4张图片及其他数据。插入3张图片时数据库操作正常,但插入4张时触发
Illuminate\Database\QueryException
错误,已尝试修改php.ini但无效。
控制器代码 #
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\game; use Illuminate\Support\Facades\Auth; class GameController extends Controller public function store(Request $request) $lastGame = Game::latest()->first(); $newIDG = $lastGame ? $lastGame->IDG + 1 : 1; $request->merge(['IDG' => $newIDG]); $request->validate([ "title" => ['required', 'string', 'unique:games'], "description" => ['required', 'string'], "main_picture" => ['required', 'image', 'mimes:jpeg,png,jpg'], 'jeux_prix' => ['required', 'numeric', 'min:20'], // 修正验证规则语法 "category". => ['required', 'string'], "download_path" => ['required', 'string'], $imagePath = $request->main_picture->getPathname(); // 获取上传文件的临时路径 $imageData = file_get_contents($imagePath); // 读取上传文件的内容 // 存储截图 if (!is_array($request->file('screenshots')) || count($request->file('screenshots')) !== 3) { return redirect()->back()->withErrors(['screenshots' => '必须上传3张截图']); foreach ($request->file('screenshots') as $screenshot) { $imagePath = $screenshot->getPathname(); // 获取上传文件的临时路径 $imageData = file_get_contents($imagePath); // 读取上传文件的内容 $imageDataArray[] = $imageData; // 将图片数据添加到数组 $data = $request->except(['main_picture', 'screenshots']); $data['etat_jeux'] = "inactif"; $data['Screen1'] = $imageDataArray[0]; $data['Screen2'] = $imageDataArray[1]; $data['Screen3'] = $imageDataArray[2]; $data['Main_picture'] = $imageData; $data['id'] = Auth::guard('creator')->id(); game::create($data); return redirect()->route('creator.dashboard.home')->with('success', '游戏添加成功!');
迁移代码 #
public function up(): void
Schema::create('games', function (Blueprint $table) {
$table->bigInteger('IDG')->primary();
$table->string('Title')->unique();
$table->string('Description')->nullable();
$table->string('Category')->nullable();
$table->integer('Jeux_Prix')->nullable();
$table->date('date_publishing')->nullable();
$table->longText('Main_Picture')->charset('binary')->nullable(); // 对应数据库LONGBLOB类型
$table->longText('Screen1')->charset('binary')->nullable(); // 对应数据库LONGBLOB类型
$table->longText('Screen2')->charset('binary')->nullable(); // 对应数据库LONGBLOB类型
$table->longText('Screen3')->charset('binary')->nullable(); // 对应数据库LONGBLOB类型
$table->string('Download_Path')->nullable();
$table->string('etat_jeux')->nullable();
$table->string('ECIN', 20)->nullable();
$table->BigInteger('id')->nullable();
$table->BigInteger('ID_Pack')->nullable();
$table->foreign('id')->references('id')->on('creators')->onDelete('cascade');