Normally, I inject class in the controller and so the methods can access to $team
object.
class TeamMemberController extends Controller {
public $team;
public function __construct(TeamRepository $team) {
$this->team = $team;
}
public function update(Request $request, $id)
{
$this->team->updateAddress($request->all(), $id);
}
I was thinking alternative pattern to create a execute()
method to keep controller slim and I wouldnt need a __construct
anymore. For example:
class TeamMemberController extends Controller {
public function update(Request $request, $id)
{
// execute updateAddress() method
execute(TeamRepository::class)->method('updateAddress',[$request->all(), $id])
// execute handle() method (default)
execute(TeamRepository::class, [$request->all(), $id]);
}
}
Inside the execute
method would use call_user_func_array
.
Do you see this is good implementation or is it bad pattern?
Aucun commentaire:
Enregistrer un commentaire