I faced this error Illuminate\Database\QueryException
That's just the type of the exception. What does the error message say?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a problem to insert into database I used WAMP server and used Laravel.
The problem is I have 4 images and other data in my form I want to import them all to the database when I try to import 3 images the insert works and when I want to insert 4 I faced this error Illuminate\Database\QueryException.
I tried to modify php ini but not work thats my Controller
<?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'], // Fixed validation rule syntax
"category". => ['required', 'string'],
"download_path" => ['required', 'string'],
]);
$imagePath = $request->main_picture->getPathname(); // Get the temporary path of the uploaded file
$imageData = file_get_contents($imagePath); // Read the contents of the uploaded file
// Store the screenshots
if (!is_array($request->file('screenshots')) ||count($request->file('screenshots')) !== 3) {
return redirect()->back()->withErrors(['screenshots' => 'You Must Import 3 Screens']);
}
foreach ($request->file('screenshots') as $screenshot) {
$imagePath = $screenshot->getPathname(); // Get the temporary path of the uploaded file
$imageData = file_get_contents($imagePath); // Read the contents of the uploaded file
$imageDataArray[] = $imageData; // Add the image data to the array
}
$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', 'Game Added successfully!');
}
}
and thats my migration
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');
// $table->foreign('ID_Pack')->references('id')->on('packs')->onDelete('cascade');
$table->timestamps();
});
}
Please or to participate in this conversation.