mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-09 21:42:57 +00:00
Add post deletion w/ confirmation, search (broken), profile page
This commit is contained in:
parent
bfb497c367
commit
827d125639
21 changed files with 374 additions and 27 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Comment;
|
||||
use App\Models\Post;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
|
@ -19,4 +20,12 @@ class DeletionController extends Controller
|
|||
$comment->delete();
|
||||
return redirect("/posts/$postid");
|
||||
}
|
||||
|
||||
public function deletePost(Post $post)
|
||||
{
|
||||
$post->featured = null;
|
||||
$post->save();
|
||||
$post->delete();
|
||||
return redirect()->route('posts.home');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
app/Livewire/Pages/Profile.php
Normal file
23
app/Livewire/Pages/Profile.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Pages;
|
||||
|
||||
use App\Models\Comment;
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
|
||||
class Profile extends Component
|
||||
{
|
||||
public User $user;
|
||||
|
||||
public function render()
|
||||
{
|
||||
$favorite_posts = $this->user->favorites()->withType(Post::class)->count();
|
||||
$favorite_comments = $this->user->favorites()->withType(Comment::class)->count();
|
||||
|
||||
return view('livewire.pages.profile', [
|
||||
'favorite_posts' => $favorite_posts, 'favorite_comments' => $favorite_comments
|
||||
])->title($this->user->name);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ class Upload extends Component
|
|||
{
|
||||
use WithFileUploads;
|
||||
|
||||
#[Validate('extensions:jpg,jpeg,bmp,gif,png,webp,apng,mp4,wmv,mkv|mimes:jpg,jpeg,bmp,gif,png,webp,apng,mp4,wmv,mkv|max:81920')]
|
||||
#[Validate('file')]
|
||||
public $file;
|
||||
|
||||
#[Validate('required|in:safe,suggestive,explicit')]
|
||||
|
|
|
|||
29
app/Livewire/Search.php
Normal file
29
app/Livewire/Search.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\User;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Spatie\Searchable\ModelSearchAspect;
|
||||
use Spatie\Searchable\Search as SpatieSearch;
|
||||
|
||||
class Search extends Component
|
||||
{
|
||||
#[Validate('string|min:3')]
|
||||
public string $searchText = '';
|
||||
|
||||
public $searchResults = [];
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.search');
|
||||
}
|
||||
|
||||
public function updated()
|
||||
{
|
||||
$this->searchResults = (new SpatieSearch())
|
||||
->registerModel(User::class, 'name')
|
||||
->perform($this->searchText);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,10 +5,11 @@ namespace App\Models;
|
|||
use MongoDB\Laravel\Eloquent\Model;
|
||||
use MongoDB\Laravel\Eloquent\SoftDeletes;
|
||||
use MongoDB\Laravel\Relations\BelongsTo;
|
||||
use Overtrue\LaravelFavorite\Traits\Favoriteable;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
use SoftDeletes, Favoriteable;
|
||||
|
||||
protected $fillable = [ 'message' ];
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ use MongoDB\Laravel\Eloquent\SoftDeletes;
|
|||
use MongoDB\Laravel\Relations\BelongsTo;
|
||||
use MongoDB\Laravel\Relations\BelongsToMany;
|
||||
use MongoDB\Laravel\Relations\HasMany;
|
||||
use Overtrue\LaravelFavorite\Traits\Favoriteable;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
use SoftDeletes, Favoriteable;
|
||||
|
||||
protected $fillable = [ 'rating', 'extension', 'featured' ];
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,21 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use MongoDB\Laravel\Auth\User as Authenticatable;
|
||||
use MongoDB\Laravel\Relations\HasMany;
|
||||
use Overtrue\LaravelFavorite\Traits\Favoriter;
|
||||
use Spatie\Searchable\Searchable;
|
||||
use Spatie\Searchable\SearchResult;
|
||||
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements Searchable
|
||||
{
|
||||
protected $connection = 'mongodb';
|
||||
protected $table = 'users';
|
||||
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
use HasApiTokens, HasFactory, Notifiable, Favoriter;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
|
@ -43,4 +45,14 @@ class User extends Authenticatable
|
|||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
|
||||
public function getSearchResult(): SearchResult
|
||||
{
|
||||
$url = url("/profiles/$this->id");
|
||||
return new SearchResult(
|
||||
$this,
|
||||
$this->name,
|
||||
$url
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue