mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
81 lines
1.6 KiB
PHP
81 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Posts;
|
|
|
|
use App\Models\Post;
|
|
use App\Models\Tag;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
|
|
class Edit extends Component
|
|
{
|
|
public Post $post;
|
|
public Collection $tags;
|
|
public Collection $selectableTags;
|
|
|
|
#[Validate('exists:tags,id')]
|
|
public string $tag = '';
|
|
|
|
#[Validate('required|in:safe,suggestive,explicit')]
|
|
public string $rating = 'unknown';
|
|
|
|
public $featured = false;
|
|
|
|
public string $deleteTagId = '';
|
|
|
|
public function mount(Post $post)
|
|
{
|
|
$this->post = $post;
|
|
$this->tags = $post->tags;
|
|
$this->rating = $post->rating;
|
|
$this->featured = $post->featured;
|
|
$this->selectableTags = Tag::whereDoesntHave('posts', function ($query) {
|
|
$query->where('id', $this->post->id);
|
|
})->get();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.posts.edit')->title("Edit post {$this->post->id}");
|
|
}
|
|
|
|
public function updated()
|
|
{
|
|
$this->validate();
|
|
|
|
if ($this->tag)
|
|
{
|
|
if ($tag = Tag::find($this->tag))
|
|
{
|
|
$this->post->tags()->attach($tag);
|
|
if ($tag->implies)
|
|
{
|
|
foreach ($tag->implies as $implied_id)
|
|
{
|
|
if ($impliedTag = Tag::find($implied_id))
|
|
{
|
|
$this->post->tags()->attach($impliedTag);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->post->rating = $this->rating;
|
|
if ($this->post->rating == 'safe')
|
|
{
|
|
$this->post->featured = $this->featured;
|
|
}
|
|
else
|
|
{
|
|
$this->post->featured = null;
|
|
}
|
|
$this->post->save();
|
|
|
|
$this->tags = $this->post->tags;
|
|
$this->selectableTags = Tag::whereDoesntHave('posts', function ($query) {
|
|
$query->where('id', $this->post->id);
|
|
})->get();
|
|
}
|
|
}
|