0

first i used the database as my driver by adding it in .env file I created the job and defined the table (product) and the row (status) to change it from zero to one in the handle method then i dispatched it in the index function in my controller with a delay of a minute and it worked well after i run php artisan queue:work but i thought it's not the right thing to do

I tried to use scheduling task by adding the logic in the schedule function in the console/kernel.php

it only works when i run php artisan schedule:run

i tried to use Task Schedular to make it run php artisan schedule:run every 1 minute but it's not working so I checked the logs it says that

"[previous exception] [object] (PDOException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel-project.jobs' doesn't exist at C:\\Users\\Youmna\\OneDrive\\Desktop\\project\\laravel-app\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:416)"
but the table is already in my phpmyadmin i tries to clear all the cache but it's not working so i tried to drop the table and migrate it again but still not working


code:

protected function schedule(Schedule $schedule): void
{
    // $schedule->command('inspire')->hourly();
    $schedule->job(new StatusJob)->everyMinute();

}

protected function commands(): void
{
    $this->load(__DIR__ . '/Commands');

    require base_path('routes/console.php');
}

public function __construct()
{
   
}
public function handle(): void
{
    
    DB::table('products')->where('status', 0)->update(['status' => 1]);
}

return new class extends Migration { public function up(): void { Schema::create('products', function (Blueprint $table) { $table->id(); $table->string('name'); $table->text('description'); $table->float('price'); $table->boolean('status')->default(0); $table->timestamps(); }); } };`

I run php artisan queue:restart didn't fix it and php artisan queue:failed show no faild jobs

enter image description here enter image description here

how to solve this please

1 Answers1

0

@Youmna, I'm sharing the migration file here, you can put it manually and run migration and verify the JOBS table is created

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateJobsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('jobs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('queue')->index();
            $table->longText('payload');
            $table->unsignedTinyInteger('attempts');
            $table->unsignedInteger('reserved_at')->nullable();
            $table->unsignedInteger('available_at');
            $table->unsignedInteger('created_at');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('jobs');
    }
}
Muneeb A.
  • 66
  • 5