0

I'm using a long alphanumerical value for my ids such as 'dc728fc9c438446c77fb1efa47513ac'. I save it in my sqlite database and it works (because I rechecked the DB), but when I try to access it in some of my views I get an incorrect id: if this id would start with numbers like '24ec46b545bc41bf8c937c441908ac3', the id I get would be '24'. If it doesn't, like above, it would be '0'.

The migration to create 'Meetings' table:

public function up()
{
    Schema::create('meetings', function (Blueprint $table) {
        $table->String('id')->unique()
        $table->String('title')
        $table->String('photoName')->nullable()
        $table->text('body')->nullable()
        $table->dateTime('dateTime')
        $table->timestamps()
    })
}

This is how I save the data in my controller:

$skpMeeting = new Meeting();
$skpMeeting->title = $title;
$skpMeeting->dateTime = $datetime0;
$skpMeeting->id = $data['id'];
$skpMeeting->save();

Then it's sent to my view like below:

$meetings = Meeting::all();

return view('home', ['meetings' => $meetings]);

And finally, my view 'home.blade.php':

<div class="card-body bg-dark">
    <a href="{{ route('meeting.show', $meeting['id']) }}" class="stretched-link text-white">{{ $meeting['id'] }}</a>
</div>

I've also tried with "$meeting->id" and I get the same result.

Any idea about how to fix it?

  • Have you properly configured your model for a string primary key? You need to set `protected $keyType = 'string';` and `public $incrementing = false;` on the model. – miken32 May 24 '22 at 19:15
  • The reason that you're getting leading numbers only is because old versions of PHP converted strings to integers this way. (e.g. `(int)"24abc" === 24)`) New versions will throw an error message instead. – miken32 May 24 '22 at 19:20

0 Answers0