X7ROOT File Manager
Current Path:
/home/gfecatvj/sites/realesbar/platform/plugins/blog/src/Services
home
/
gfecatvj
/
sites
/
realesbar
/
platform
/
plugins
/
blog
/
src
/
Services
/
📁
..
📁
Abstracts
📄
StoreCategoryService.php
(661 B)
📄
StoreTagService.php
(1.49 KB)
Editing: StoreTagService.php
<?php namespace Botble\Blog\Services; use Botble\Base\Events\CreatedContentEvent; use Botble\Blog\Models\Post; use Botble\Blog\Services\Abstracts\StoreTagServiceAbstract; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class StoreTagService extends StoreTagServiceAbstract { /** * @param Request $request * @param Post $post * @return mixed|void */ public function execute(Request $request, Post $post) { $tags = $post->tags->pluck('name')->all(); $tagsInput = collect(json_decode($request->input('tag'), true))->pluck('value')->all(); if (count($tags) != count($tagsInput) || count(array_diff($tags, $tagsInput)) > 0) { $post->tags()->detach(); foreach ($tagsInput as $tagName) { if (!trim($tagName)) { continue; } $tag = $this->tagRepository->getFirstBy(['name' => $tagName]); if ($tag === null && !empty($tagName)) { $tag = $this->tagRepository->createOrUpdate([ 'name' => $tagName, 'author_id' => Auth::user()->getKey(), ]); $request->merge(['slug' => $tagName]); event(new CreatedContentEvent(TAG_MODULE_SCREEN_NAME, $request, $tag)); } if (!empty($tag)) { $post->tags()->attach($tag->id); } } } } }
Upload File
Create Folder