Skip to content

Instantly share code, notes, and snippets.

@Michael-Stokoe
Last active January 30, 2020 16:05
Show Gist options
  • Save Michael-Stokoe/7d31df97bff5dbe2f5058f450c0636d4 to your computer and use it in GitHub Desktop.
Save Michael-Stokoe/7d31df97bff5dbe2f5058f450c0636d4 to your computer and use it in GitHub Desktop.
Create/Update method for Laravel.
<?php
public function crupdate($id = null, Request $request)
{
$fields = $request->only(['field_1', 'field_2']);
$model = Model::updateOrCreate(
[
'id' => $id
],
$fields
);
return redirect()->route('your.destination');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment