I am writing an application with the repositories concept in php with laravel framework.
In my controller I have this method:
/**
* Update the specified resource in storage.
* PUT /locais/{id}
*
* @param int $id
* @return Response
*/
public function update($id)
{
$data = Input::all();
$data['str_categories'] = implode(',', $data['categories']);
$this->place->update($id, $data);
return Redirect::route('locais.index');
}
I am concerned about this line in controller:
$data['str_categories'] = implode(',', $data['categories']);
This line can be in controller method? Or this is a responsibility of places repository?
1 Answer 1
Logic or data transformation should usually be moved out of the controller. Your places repository seems like a better choice for the implode
. After all, one of the major purposes of repositories is to decouple data handling and storage as much as possible from other parts of the application, including controller.s