Пример #1
0
 public function tagList($id)
 {
     $results = Tag::where_in('article_id', $id)->get();
     $output = array();
     foreach ($results as $tag) {
         $output[$tag->tag_name] = $tag;
     }
 }
Пример #2
0
 /**
  * Function that it will handle with post creation and validate all fields of creation
  * @todo Fix upload bug , since when we dont specify a cover it will try upload something
  */
 public function post_new()
 {
     $new_post = Input::all();
     unset($new_post['csrf_token']);
     unset($new_post['tags']);
     $new_post['slug'] = Str::slug($new_post['title']);
     $rules = array('title' => 'required|min:3|max:255', 'cover' => 'image', 'title' => 'required|unique:articles');
     $validation = Validator::make($new_post, $rules);
     if ($validation->fails()) {
         return Redirect::to('dojo/articles')->with('user', Auth::user())->with_errors($validation)->with_input();
     }
     //Tag handler
     $tags = Tag::input('tags');
     $tag_ids = array_values(array_map(function ($tag) {
         return $tag->id;
     }, $tags));
     # cover upload handler
     if (!empty($new_post['cover']['name'])) {
         $extension = File::extension($new_post['cover']['name']);
         $directory = path('public') . 'images/thumbnails/articles/';
         $filename = sha1(time()) . ".{$extension}";
         $upload_sucess = Input::upload('cover', $directory, $filename);
         if ($upload_sucess) {
             $new_post['cover'] = URL::to('images/thumbnails/articles/' . $filename);
         }
     } else {
         unset($new_post['cover']);
     }
     $new_article = new Article($new_post);
     $new_article->save();
     $new_article->tags()->sync($tag_ids);
     return Redirect::to('dojo/articles/');
 }