I've got 2 classes in my application both have their own Controller. Week -> WeekController Day -> DayController
When a new week is created I also want to create 5 (work)days for that week.
At this point I make a call from the create method in the WeekController to the create method in the DayController:
app('App\Http\Controllers\DayContoller')->create($week->id);
This post mentions this as being a bad practice. The alternatives offered however don't seem better in my case: A week doesn't really extend a day and using a trait would feel strange to me in this scenario as well.
So I wonder, what's the best solution in this scenario. I'm pretty sure this is something that's pretty common.
UPDATE: Not quite sure if this is better but I already rewrote as follows: I'm now injecting the DayController in the create method of the WeekController.
create(DayController $dayController, $id)
UPDATE2: I wrote a closure function in my route where I call a new written service.
function(CreateWeek $createWeek, $id)
{
$createWeek->createWeekWithDays($id);
} ]);
In this service I have a constructor that instantiates my 2 Controllers
public function __construct(WeekController $weekController, DayController $dayController)
{
$this->weekController = $weekController;
$this->dayController = $dayController;
}
and finally the createWeekWithDays method:
public function createWeekWithDays($id)
{
//Create the week
$newId = $this->weekController->create($id);
// Create the days
$this->dayController->createDays($newId);
}
I don't know what's the best solution...