public function run() { $array = array(['title' => 'Artikel', 'slug' => 'uncategorized']); foreach ($array as $item) { Postcategory::create($item); } }
/** * Update the specified post in storage. * * @param int $id * @return Response */ public function update($id) { $post = Post::findOrFail($id); $file = Input::file('image'); $category = Postcategory::find(Input::get('post_category_id')); $data = array('title' => ucwords(Input::get('title')), 'slug' => $this->slugify(Input::get('slug')), 'content' => Input::get('content'), 'excerpt' => Input::get('excerpt'), 'post_category_id' => Input::get('post_category_id'), 'status' => Input::get('status'), 'comment_status' => Input::get('comment_status'), 'social_status' => Input::get('social_status'), 'created_at' => Input::get('created_at')); $validator = Validator::make($data, Post::rules($id)); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } if (Input::hasFile('image')) { // checking file is valid. if (Input::file('image')->isValid()) { $destinationPath = '/uploads/' . $category->slug; // upload path $extension = Input::file('image')->getClientOriginalExtension(); // getting image extension $fileName = rand(1, 1000) . '_' . $data['slug'] . '.' . $extension; // renameing image Input::file('image')->move(public_path() . $destinationPath, $fileName); // uploading file to given path $data['image'] = $destinationPath . "/" . $fileName; } else { // sending back with error message. return Redirect::back()->with('errors', 'Uploaded file is not valid')->withInput(); } } if (Input::hasFile('documents')) { $documents = Input::file('documents'); foreach ($documents as $newdocument) { if ($newdocument !== NULL) { // dd($newdocument); // checking file is valid. $destinationPath = '/uploads/documents'; // upload path $fileName = rand(1, 1000) . '_' . $newdocument->getClientOriginalName(); // renameing image $newdocument->move(public_path() . $destinationPath, $fileName); // uploading file to given path // Save the photo $document = new Document(); $document->name = $fileName; $document->path = $destinationPath . "/" . $fileName; $document->save(); $post->documents()->save($document); } } } if (Input::has('related_members')) { $post->members()->sync(Input::get('related_members')); } $post->update($data); return Redirect::route('admin.posts.edit', $post->id)->with("message", "Data berhasil disimpan"); }
/** * Remove the specified Postcategory from storage. * * @param int $id * @return Response */ public function destroy($id) { Postcategory::destroy($id); return Redirect::route('categories.index'); }