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');
 }
Exemple #2
0
 public function filterColumnValue($row, string $field, $value, array $column = null)
 {
     if (is_string($value)) {
         $length = strlen($value);
         if ($length > 0) {
             if (isset($column['summary']) && is_numeric($column['summary']) && $column['summary'] > 0) {
                 $value = $this->label(str_summary($value, $column['summary']), null, ['title' => $value]);
             } elseif (isset($column['strLen']) && is_numeric($column['strLen']) && $column['strLen'] > 0) {
                 $value = $this->label(str_len_cut($value, $column['strLen']), null, ['title' => $value]);
             } elseif (isset($column['strWidth']) && is_numeric($column['strWidth']) && $column['strWidth'] > 0) {
                 $value = $this->label(str_width_cut($value, $column['strWidth']), null, ['title' => $value]);
             }
         }
     } elseif (!empty($column['timestamp'])) {
         if (is_numeric($value) && $value > 0) {
             $value = date('Y-m-d H:i:s', $value);
         } else {
             $value = $this->getText(self::TEXT_NONE);
         }
     }
     if (isset($column['options'])) {
         $value = $column['options'][$value] ?? $value;
     }
     if (isset($column['before']) || isset($column['after'])) {
         $value = $this->wrap($value, $column['before'], $column['after'], $column['wrap'] ?? [], 'div');
     }
     if ($row instanceof Model) {
         if (isset($column['getter']) && is_callable([$row, $column['getter']])) {
             $value = call_user_func([$row, $column['getter']]);
         }
     }
     // todo: 这里会增加一些Model默认属性的处理
     if (isset($column['onShow']) && is_callable($column['onShow'])) {
         $value = call_user_func($column['onShow'], $this, $row, $value, $column);
     }
     return $value;
 }