You could just do this:
if ( Input::get( 'featured' ) == 'yes' )
{
$annonce->featured = Input::get( 'featured' );
}
And save you from repeating everything.
edit: Won't Input::get( 'featured' ) give a null response for an unchecked checkbox anyway? You could just keep it in there and not even bother with the if statement.
Hey Chris,
Thanks! Worked perfectly what you suggested.
On a sidenote I tried what you suggested in your edit, however I got an error telling me that it could indeed not be null, so I guess the if statement is needed.
if you really want to clean up your controllers you should move that entire part into a repository, controllers should not have business logic in them in my opinion.
your controller would look like this
<?php
use Dummy\Repositories\Contracts\AnnonceRepositoryInterface;
class DummyController extends Controller {
public function __construct(AnnonceRepositoryInterface $annonce)
{
$this->annonce = $annonce;
}
public function create()
{
return View::make('annonce.create');
}
public function store()
{
return ($annonce = $this->annonce->save(Input::all())) ?
Redirect::route('annonce.overview')
->with('message', trans('messages.annonce.store', compact('annonce'))) :
Redirect::back()->withInput()->withErrors($this->annonce->getErrors());
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community