forked from eatvio/eatvio-infra
make static analyz for blogPost
This commit is contained in:
@@ -7,6 +7,9 @@ use App\Models\Tag;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class Edit extends Component
|
||||
{
|
||||
@@ -14,21 +17,24 @@ class Edit extends Component
|
||||
|
||||
public BlogPost $blogPost;
|
||||
|
||||
public $image;
|
||||
public string|UploadedFile $image;
|
||||
|
||||
public $state = 'archived';
|
||||
public string $state = 'archived';
|
||||
|
||||
public $title = '';
|
||||
public string $title = '';
|
||||
|
||||
public $description = '';
|
||||
public string $description = '';
|
||||
|
||||
public $tags = [];
|
||||
public Collection|array $tags = [];
|
||||
|
||||
public $videoUrl = '';
|
||||
public string $videoUrl = '';
|
||||
|
||||
protected $listeners = ['blogPostTagAdded', 'blogPostTagRemoved'];
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['blogPostTagAdded', 'blogPostTagRemoved'];
|
||||
}
|
||||
|
||||
public function mount(BlogPost $blogPost)
|
||||
public function mount(BlogPost $blogPost): void
|
||||
{
|
||||
// $this->name = $blogPost->name;
|
||||
$this->image = $blogPost->image;
|
||||
@@ -39,13 +45,13 @@ class Edit extends Component
|
||||
$this->videoUrl = $blogPost->youtube_url;
|
||||
}
|
||||
|
||||
public function parentComponentTagAdded(Tag $tag)
|
||||
public function parentComponentTagAdded(Tag $tag): void
|
||||
{
|
||||
$tagIndex = $tag->id;
|
||||
$this->tags[$tagIndex] = $tag;
|
||||
}
|
||||
|
||||
public function parentComponentTagRemoved($tag)
|
||||
public function parentComponentTagRemoved(Tag $tag): void
|
||||
{
|
||||
$tagToDetach = Tag::where('name', $tag)->first();
|
||||
$this->tags = collect($this->tags)
|
||||
@@ -55,19 +61,19 @@ class Edit extends Component
|
||||
$this->blogPost->tags()->detach($tagToDetach->id);
|
||||
}
|
||||
|
||||
public function draft()
|
||||
public function draft(): void
|
||||
{
|
||||
$this->state = 'archived';
|
||||
$this->publish();
|
||||
}
|
||||
|
||||
public function preview()
|
||||
public function preview(): void
|
||||
{
|
||||
$this->state = 'archived';
|
||||
$this->publish();
|
||||
}
|
||||
|
||||
public function publish()
|
||||
public function publish(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
@@ -88,15 +94,15 @@ class Edit extends Component
|
||||
$user = Auth::user();
|
||||
$user->author_of_blog_post()->attach($post->id);
|
||||
|
||||
return redirect()->route('blog_post.show', $post->id);
|
||||
$this->redirectRoute('blog_post.show', $post);
|
||||
}
|
||||
|
||||
public function render()
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.blog-post.edit');
|
||||
}
|
||||
|
||||
protected function rules()
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
/* 'image' => 'required|image|max:2048', */
|
||||
|
||||
Reference in New Issue
Block a user