Ejemplo n.º 1
0
 public function store(StoreBlogPostRequest $request)
 {
     $id = $request->input('id');
     $title = $request->input('title');
     $content = $request->input('content');
     $summary = str_summary($content, 100);
     $thumb_img = $request->input('thumb_img');
     $category = $request->input('category');
     $tags = $request->input('tags');
     if ($id) {
         $post = Post::find($id);
     } else {
         $post = new Post();
         $post->author = Auth::user()->id;
     }
     $post->title = $title;
     $post->summary = $summary;
     $post->content = $content;
     $post->thumb_img = $thumb_img;
     $post->save();
     $relations = [];
     $relations[] = ['term_id' => $category];
     if ($tags) {
         foreach ($tags as $tag) {
             $relations[] = ['term_id' => $tag];
         }
     }
     if ($relations) {
         $post->save_relations($relations);
     }
     return redirect()->action('Admin\\PostController@index');
 }