Created
June 19, 2017 12:21
-
-
Save LasseRafn/58910f8d21b5869dfb8562489d7f1570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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