I'm quite new to Laravel, and I'm not sure what am I doing is the best practice.
I'd like to return JSON if the request is Ajax, or return a view otherwise. This is the way I made it, and it works fine, but I'm not sure if this is the best way(it seems long winded). I'd really like to hear your suggestions.
public function store()
{
$input = Input::all();
if(!$this->settings->fill($input)->isValid())
{
if ( Request::ajax() ){
return $this->jsonFailure(array(
'errors' => $this->settings->errors
));
}
else{
return Redirect::route('admin.settings.create')
->withInput()
->withErrors($this->settings->errors);
}
}
$this->settings->save();
if ( Request::ajax() )
return $this->jsonSuccess('success');
else
Redirect::route('admin.settings.index');
}