The text fields can handle 64Kb which is 65,536 bytes. If that is too little try changing it to longtext.
Jan 17, 2021
4
Level 4
Data too long for column 'payload' at row 1
I'm showing the recently viewed deals on the homepage to my visitors. This only works for one viewed item, after that the following QueryExeption occurs:
Illuminate\Database\QueryException
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'payload' at row 1 (SQL: update `sessions` set `payload` =.....
I took this from the docs - Driver Prerequisites
My first thought was to change the column 'payload' to a varchar or longtext field. But there must be a reason why it's not used like that in the docs, right.
What should i do to fix this?
- Store more specific data to the session
- Or change the fieldtype "payload" in the database
- Or something else
This is my sessions table:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSessionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->text('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sessions');
}
}
in my DealsController this is how i store info to the session. It returns a massive array.
<?php
namespace App\Http\Controllers;
use App\Models\Deal;
use App\Filters\DealFilters;
use App\Models\Category;
use App\Models\City;
use App\Models\Address;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
class DealController
{
public function show(Request $request, $countrySlug, $citySlug, Category $category, Address $address, Deal $deal)
{
$city = City::where('country_slug', $countrySlug)->where('slug', $citySlug)->firstOrFail();
$dealIds = collect(session()->get('deals', []))->pluck('id');
if ($dealIds->contains($deal->getKey()) && $index = $dealIds->search($deal->getKey())) {
session()->pull("deals.{$index}");
}
session()->push('deals', $deal);
$mediaItems = $deal->getMedia('multi_collection');
$imagesPerChunk = count($mediaItems);
return view('deals.show', [
'city' => $city,
'category' => $category,
'address' => $address,
'deal' => $deal,
'mediaItems' => $mediaItems,
'imagesPerChunk' => $imagesPerChunk
]);
}
}
Please or to participate in this conversation.