mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
update
This commit is contained in:
parent
afc1fb10bc
commit
8004c8d69e
12 changed files with 320 additions and 5 deletions
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Livewire\Posts;
|
||||
|
||||
use App\Models\Post;
|
||||
use App\Models\Comment as PostComment;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
|
|
@ -11,12 +13,24 @@ class View extends Component
|
|||
public Post $post;
|
||||
|
||||
#[Validate('string|max:240')]
|
||||
public $comment = '';
|
||||
public string $message = '';
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.posts.view', [
|
||||
// 'comments' => $this->post->comments
|
||||
'comments' => $this->post->comments->sortByDesc('created_at'),
|
||||
])->title("Post {$this->post->id}");
|
||||
}
|
||||
|
||||
public function postComment()
|
||||
{
|
||||
$this->validate();
|
||||
$user = Auth::user();
|
||||
if ($comment = PostComment::create(['message' => $this->message]))
|
||||
{
|
||||
$this->post->comments()->save($comment);
|
||||
$user->comments()->save($comment);
|
||||
}
|
||||
return $this->redirect("/posts/{$this->post->id}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue