I'm trying to use one form for both creates and updates. Both actions save through this method:
public function store() {
$data = Input::all();
$data['company_id'] = Auth::user()->company_id;
$validator = Validator::make($data, Feature::$rules);
if($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
Feature::firstOrNew(['id' => Input::get('id')])->update($data);
return Redirect::route('features.index');
}
How can I rewrite this line:
Feature::firstOrNew(['id' => Input::get('id')])->update($data);
So that it doesn't fetch the object from the database first? There's no need for that; I'm not doing anything with it. It should either issue a INSERT
if Input::get('id')
is set, or an UPDATE
if it's not.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…