Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andriw's avatar
Level 1

Job queque not creating DB laravel 11

Hi have a great day, im glad if any expert wanna help me. do anyone know why my queque job didnt creating data to DB ?, but at the terminal its said DONE, im using laravel 11

in Jobs/Prize5.php;

     public function handle(): void
{
    $games= Game::all();
    foreach ($games as $game) {
        $angkaUnik = range(0,9);
        shuffle($angkaUnik);
        $prize5 = implode('',array_slice($angkaUnik,0,6));

        $data = [
            'id_game'=>$game->id,
            'prize5'=> $prize5,
        ];

        Result::create($data);
    }
}

then in routes/console.php

$timer = Timer::all();

Schedule::job(new Prize5())->dailyAt('[$timer->prize5]');

0 likes
9 replies
Snapey's avatar

you are using mass assignment so make sure fields are fillable or unguarded in your model

1 like
andriw's avatar
Level 1

@Snapey thanks for ur response master, im new learn in laravel, glad if u wanna tell me how to do step by step

anyway this is my model Result.php

protected $table = 'result'; protected $guarded = ['id'];

andriw's avatar
Level 1

@Snapey i just added fillable to my model like this

protected $fillable = [
    'prize1',
    'prize2',
    'prize3',
    'prize4',
    'prize5',
];
Snapey's avatar

@andriw ok so you set $guarded and all other columns are not mentioned, so can be filled. This is not the issue.

1 like
Snapey's avatar

@andriw Don't have both $fillable and $guarded. One or the other.

1 like
andriw's avatar
Level 1

@Snapey ig i need $guarded = ['id']; cause my prize 5 have relationship with id_game in Game.php, i just try to do this manual with route

Route::post('managePrize/{id}/createAutomatic',[ResultController::class, 'createAutomatic'])->name('managePrize.createAutomatic');

its work but when i changed to job its not created, any solution master ?

Snapey's avatar

@andriw make sure you don't have any logic that checks who the user is when accessing these models

A job has no request so cannot get any input, session or user data

1 like
andriw's avatar
Level 1

@Snapey i just change my model to normal with just added guarded id n remove fillable its work for manual action, sorry for my english

andriw's avatar
Level 1

@Snapey this case solved by changing QUEUE_CONNECTION=database to QUEUE_CONNECTION=sync in .env, anyway thanks master have a good time, im sorry if i disturb u

Please or to participate in this conversation.