public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Snippet::create([]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { //validate $validationErrors = Snippet::validate(Input::all()); if ($validationErrors) { return Redirect::route("newSnippet"); } $newSnippet = Snippet::create(array("snippet" => Input::get('snippet'))); if ($newSnippet) { return Redirect::route('showSnippet', $newSnippet->id); } }
<?php Route::get('snippets/create', function () { if (!($user = Auth::user())) { return array('error' => 'You must be logged in to create a snippet.'); } $input = Input::all(); $rules = array('title' => 'required|max:255'); $validated = Validator::make($input, $rules); if ($validated->fails()) { return array('error' => $validated->errors); } if ($id = Snippet::create($user->id, $input['title'], @$input['description'])) { return Redirect::to('snippets/' . $id); } });