2
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.