Support the ongoing development of Laravel.io →
Input Eloquent Architecture
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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());
    }

}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Reached reached Joined 27 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.