Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Base Class instead of Concern #49

Open
Sairahcaz opened this issue Mar 3, 2024 · 1 comment
Open

Idea: Base Class instead of Concern #49

Sairahcaz opened this issue Mar 3, 2024 · 1 comment

Comments

@Sairahcaz
Copy link

Hi Mateus, thanks for this cool package!

An idea I had, was to change the Concern to a Base Class.
This would make the API look much more natural imho:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\Podcast;
use Junges\TrackableJobs\Models\TrackedJob;
use Junges\TrackableJobs\TrackableJob;

class ProcessPodcastJob extends TrackableJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(Podcast $podcast)
    {
         parent::__construct($podcast);
         
         // Add your code here.
    }

    public function handle()
    {
        //
    }
}

VS:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Junges\TrackableJobs\Concerns\Trackable;
use App\Models\Podcast;
use Junges\TrackableJobs\Models\TrackedJob;

class ProcessPodcastJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Trackable {
        __construct as __baseConstruct;
    }

    public function __construct(Podcast $podcast)
    {
         $this->__baseConstruct($podcast);
         
         // Add your code here.
    }

    public function handle()
    {
        //
    }
}

What do you think?

@Sairahcaz Sairahcaz changed the title Idea: Base Class instead Concern Idea: Base Class instead of Concern Mar 3, 2024
@mateusjunges
Copy link
Owner

Hey 👋 this is actually one of the things I'm considering for v2. I'm not sure if I'll go with this yet, but I have to agree that the first one looks way better than using a trait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants