mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-09 21:42:57 +00:00
update
This commit is contained in:
parent
afc1fb10bc
commit
8004c8d69e
12 changed files with 320 additions and 5 deletions
22
app/Http/Controllers/DeletionController.php
Normal file
22
app/Http/Controllers/DeletionController.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Comment;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DeletionController extends Controller
|
||||
{
|
||||
public function deleteComment(Comment $comment)
|
||||
{
|
||||
if (Auth::id() != $comment->user->id)
|
||||
{
|
||||
abort(401);
|
||||
}
|
||||
|
||||
$postid = $comment->post->id;
|
||||
$comment->delete();
|
||||
return redirect("/posts/$postid");
|
||||
}
|
||||
}
|
||||
16
app/Livewire/Posts/Comment.php
Normal file
16
app/Livewire/Posts/Comment.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Posts;
|
||||
|
||||
use App\Models\Comment as PostComment;
|
||||
use Livewire\Component;
|
||||
|
||||
class Comment extends Component
|
||||
{
|
||||
public PostComment $comment;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.posts.comment');
|
||||
}
|
||||
}
|
||||
|
|
@ -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}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
24
app/Models/Comment.php
Normal file
24
app/Models/Comment.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use MongoDB\Laravel\Eloquent\SoftDeletes;
|
||||
use MongoDB\Laravel\Relations\BelongsTo;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [ 'message' ];
|
||||
|
||||
public function post(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,12 +5,16 @@ namespace App\Models;
|
|||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use MongoDB\Laravel\Eloquent\SoftDeletes;
|
||||
use MongoDB\Laravel\Relations\BelongsTo;
|
||||
use MongoDB\Laravel\Relations\BelongsToMany;
|
||||
use MongoDB\Laravel\Relations\HasMany;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [ 'rating', 'extension', 'featured' ];
|
||||
|
||||
public function user(): BelongsTo
|
||||
|
|
@ -23,6 +27,11 @@ class Post extends Model
|
|||
return $this->belongsToMany(Tag::class);
|
||||
}
|
||||
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
|
||||
protected function toBase64(string $path): string
|
||||
{
|
||||
$ext = $this->extension;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ class User extends Authenticatable
|
|||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
|
|
@ -39,4 +38,9 @@ class User extends Authenticatable
|
|||
{
|
||||
return $this->hasMany(Post::class);
|
||||
}
|
||||
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue