Skip to content

Instantly share code, notes, and snippets.

@LasseRafn
Created June 19, 2017 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LasseRafn/58910f8d21b5869dfb8562489d7f1570 to your computer and use it in GitHub Desktop.
Save LasseRafn/58910f8d21b5869dfb8562489d7f1570 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ProductStoreRequest extends FormRequest
{
public function rules()
{
return [
'name' => 'required',
// ...
];
}
public function handle()
{
$product = new Product;
$product->name = $this->name;
return $product;
}
}
// ------- CONTROLLER --------
class ProductController extends Controller
{
// ...
public function store( ProductStoreRequest $request )
{
$product = $request->handle();
return redirect()->action( 'ProductController@show', $product->slug )
->with( 'success', 'Product created!' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment