Hello, everyone, I am working on saving notifications in the notification table which is working fine but the primary key of the tables are being generated randomly instead of auto-incrementing, how can I fix it
{
Schema::create(
'notifications', function (Blueprint $table){
$table->bigIncrements('id');
$table->bigInteger('user_id');
$table->text('type', 30);
$table->text('data');
$table->tinyInteger('is_read');
$table->timestamps();
}
);
}``` This is the migration file of the table
@sinnbeck, one use case I am using this for is notifying users when they are assigned to be a project manager what I did was in the controller that is used to assign users as PM, i added this code
I dont see any reason why that would break the auto increment. It seems that it is setting the ID manually, but I wonder what part of laravel would do that. Debugbar should show that
Then make a simple route (perhaps just a get route with a view), where you do the dispatch. Then open debugbar on the page (down in the bottom to the left), and select the Queries tab. Here you can see all queries that was run on the page
I had the same issue! The problem is (I think) the following: Laravels default notifications setup uses a UUID instead of an incrementing integer for the primary key of the Notifications table. You're fine to change that as you did, but you also have to tell Laravel to generate an integer instead of a string. Ohteriwse it probably takes the first integers in the UUID it generated and fill that, causding the random id values.
You can do this in your notifications model. Since your model extends DatabaseNotification, you need to override the settings on DatabaseNotification. Set these two values in your Notification model. It fixed the problem for me!
class Notification extends DatabaseNotification
{
protected $keyType = 'integer';
public $incrementing = true;