Any business logic should be placed in models, or repositories and your controller should look just like
<?php
class DealsController extends controller {
public function __construct(Deals $deals) //// <---- Dependency Injection
{
$this->deals = $deals;
}
public function store()
{
try
{
$this->deals->insertRow(Input::all());
}
catch (\Exceptions\ValidationException $e)
{
return Redirect::back()
->withInput()
->withErrors($this->deals->errors);
}
return Redirect::to('deals/create')
->with('message', 'Deal Created');
}
}
And in your Deals class, you do whatever you need to do with your data
class Deals extends Eloquent {
public function insertRow($input)
{
$validation = new Services\Validators\Deal;
if($validation->passes())
{
$deals = Deals::create($input);
// start code in question
$image = $input['company'];
$image = strtolower($image);
$image = str_replace(" ", "-", $image);
$image .= ".png";
$deals->image = $image;
$deals->save();
// end code in question
}
$this->errors = $validation->errors;
throw new \Exceptions\ValidationException("Error inserting Deals", $validation->errors);
}
}
This is untested and a not-really-refactored code, but I hope you can see a point in it.