laravel-gymie
laravel-gymie copied to clipboard
Clean up the controllers and treating exceptions
Would be great clean up the controllers and move the extra logical code to repositories or models.
I realized that when a problem occurs with the DB::transaction, the controllers are not firing the exception, but only returning a error message. It is very difficult to track the errors occurred when saving or updating data.
Ex:
DB::beginTransaction();
try {
...
} catch (\Exception $e) {
DB::rollback();
// I think here we can throw an exception, with the message below. Then, on the
// exceptions handler, we check if the system env is dev or production, to show the error
// or only flash the message.
flash()->error('Error while creating the member');
return redirect(action('MembersController@index'));
}
I think it's too early to tackle down exception even because on Laravel 5.5 and 5.6 you can handler everything using the renderable interface
@TiagoSilvaPereira, not just controllers we will need refactoring at lot more places, currently working on the items list for the same.