current(); $query= parent::listQuery(); if(Str::contains($currentUrl, 'project_articles')){ $query->where('type', ProjectArticle::TYPE_ARTICLE); }elseif(Str::contains($currentUrl, 'project_flows')){ $query->where('type', ProjectArticle::TYPE_FLOW); }elseif(Str::contains($currentUrl, 'project_photos')){ $query->where('type', ProjectArticle::TYPE_PHOTO); }elseif(Str::contains($currentUrl, 'project_advances')){ $query->where('type', ProjectArticle::TYPE_ADVANCE); } return $query; } public function store($data): bool { $columns = $this->getTableColumns(); $model = $this->getModel(); $isEnable = Arr::get($data, 'is_enabled'); $publishedAt = Arr::get($data, 'published_at'); if ($isEnable && empty($publishedAt)) { $data['published_at'] = now(); } $data['cover'] = $this->saveImage('cover', 'project_articles/cover')[0] ?? ''; $data['appendixes'] = $this->saveFile('appendixes', 'project_articles/appendixes'); foreach ($data as $k => $v) { if (!in_array($k, $columns)) { continue; } $model->setAttribute($k, $v); } return $model->save(); } public function update($primaryKey, $data): bool { $columns = $this->getTableColumns(); $model = $this->query()->whereKey($primaryKey)->first(); $isEnable = Arr::get($data, 'is_enable'); $publishedAt = Arr::get($data, 'published_at'); if ($isEnable && empty($publishedAt) && empty($model->published_at)) { $data['published_at'] = now(); } if(isset($data['cover'])){ $data['cover'] = $this->saveImage('cover', 'project_articles/covers')[0] ?? ''; } if(isset($data['appendixes'])){ $data['appendixes'] = $this->saveFile('appendixes', 'project_articles/appendixes'); } foreach ($data as $k => $v) { if (!in_array($k, $columns)) { continue; } $model->setAttribute($k, $v); } return $model->save(); } }