简体   繁体   中英

How tags are used with Laravel Horizon

My tracking tags in job queue does not show the tags I expect. Job does not process after change to class.

My job example class is :

class EmailUser implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * The user instance.
     *
     * @var \App\User
     */
    public $user;

    /**
     * Create a new job instance.
     *
     * @param  \App\User  $user
     * @return void
     */
    public function __construct(User  $user)
    {
        $this->user = $user;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Mail::to('fesher@example.com')->send(new ApplicationReceivedEmail());
    }

   /**
     * Get the tags that should be assigned to the job.
     *
     * @return array
     */
    public function tags()
    {
        return ['email', 'user:'.$this->user];
    }
}

Now before I manually tag job class emails are sent normally and all works. Adding tags method kills process, emails are no longer sent normally.

I go from example on website here https://laravel.com/docs/5.5/horizon#tags

Someone can help? Thanks

You are trying to concatenate an Eloquent collection to the tag string where it should be something like a name or ID .

Change:

    return ['email', 'user:'.$this->user];

To:

    return ['email', 'user:'.$this->user->id];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM