samedi 13 juillet 2019

Laravel Lucid Architecture dependency injection

I am new to Lucid Architecture applied with Laravel.

I am trying to find the best way to inject dependencies into my features. Here is my users' page feature:

class UsersPageFeature extends Feature {

    public function handle( Request $request,User $user ) {
        $data                       = [];
        $users           = $this->run( GetUsersJob::class,['userModel'=> $user );
        $data['users']       = $users;
        return $this->run( new RespondWithViewJob( "web::pages.users.page",  $data) );
    }
}

And my GetUsersJob:

class GetUsersJob extends Job {

    public function __construct($user) {
        $this->user = $user;
    }

    public function handle( ) {
        return $user->all();
    }
}

It works however, I need to pass all dependencies to each job. I think this could be done better.

Please suggest a better way.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire