Skip to content

Instantly share code, notes, and snippets.

@rfmeier
Created November 7, 2017 17:45
Show Gist options
  • Save rfmeier/b848440a7af6c88c1e4992c74007eb2e to your computer and use it in GitHub Desktop.
Save rfmeier/b848440a7af6c88c1e4992c74007eb2e to your computer and use it in GitHub Desktop.
Simple controller model update in Laravel.
<?php
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Product $product
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Product $product)
{
$this->validate($request, [
'name' => 'required|max:255',
'price' => 'required|numeric',
]);
$product->update(
$request->only('name', 'price')
);
return back()->with('status', 'The product was updated!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment