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

wizard2000's avatar

id of job in laravel 10

hi , i want to publish a post in a date defined by a user (for example i want to change the status column of related DB from 'pending' to 'published' at next month), i think Jobs is best option to do that, but if by any reason i want to change the publishing date i should change the delay of column in jobs table in mysql,

public function update($request $post){
//i want to change  the delay time or reserved or deleted the job that created before 
$theJob=dispatch(new PublishingPostJob ($post))->delay(//time)
}

``
how can i get the id of the job? (when i dump $theJob id, uuid are null)
0 likes
5 replies
wizard2000's avatar

@ignaciodev i dont get it alomist every one said that in laravel 10 it is impossible, is there an other way to this ?

ignaciodev's avatar

But wouldn't it be easier to simply add a published_at column to your Post model? Then you can have a method like $post->isPublished() that simply returns $post->published_at->isPast().

(Not sure what you're trying to build, but I know I made the mistake in the past of using jobs for things that can be done much easier with timestamps!)

wizard2000's avatar

@ignaciodev Actually i have to upload some posts for next to month. Until publish_at no one can access and see these pages but after this date they will be publiced . Because the for each post is different in day and time i decided to use job. But if i want to change the date of publish i have to change the delay time or reserved time of jobs table or delete it and dispatch new job. So for each job i have to have the related job. Ib laravel 10 dispatch methit does nit return the job instance instead return pending job that does not have any date related to dispatched job

ignaciodev's avatar

@wizard2000 have you looked at local scopes? You could scope it so that only the posts with a past published_at timestamp are fetched, then you avoid jobs all together:

class Post extends Model
{
    public function scopePublished($query)
    {
        $query->where('published_at', '<=', now());
    }
}

And then:

$posts = Post::published()->get();

You can read it here:

https://laravel.com/docs/10.x/eloquent#local-scopes

Please or to participate in this conversation.