feat: basic quotes request

This commit is contained in:
Nicholas Ciechanowski 2023-10-07 20:48:36 +11:00
parent 4fdff98580
commit a918600813
12 changed files with 165 additions and 24 deletions

View File

@ -102,6 +102,21 @@ class CreateUserCommand extends Command
hint: 'One will be randomly generated if non is provided',
);
// If we're not randomly generating one, let's make sure they're the same.
// If they fucked it up and don't know what the first password is they're fucked.
if (!empty($password)) {
password(
label: 'Confirm password?',
placeholder: '**********',
validate: function (string $value) use ($password) {
if ($value !== $password) {
return "Passwords don't match";
}
},
hint: 'One will be randomly generated if non is provided',
);
}
if (empty($password)) {
$password = Str::password(12);
$this->info("Randomly Generated Password: $password");

View File

@ -3,23 +3,13 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Quote extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'last_used',
'quote',
'times_used',
];
use SoftDeletes;
protected $casts = [
'created_at' => 'datetime',
'last_used' => 'datetime',
'updated_at' => 'datetime',
protected $fillable = [
'quote',
];
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class RequestedQuotes extends Model
{
use SoftDeletes;
protected $fillable = [
'quote',
'user_id',
];
}

View File

@ -11,8 +11,7 @@ return new class extends Migration
Schema::create('quotes', function (Blueprint $table) {
$table->id();
$table->string('quote');
$table->integer('times_used')->default(0);
$table->timestamp('last_used')->nullable();
$table->softDeletes();
$table->timestamps();
});
}

View File

@ -0,0 +1,25 @@
<?php
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('requested_quotes', function (Blueprint $table) {
$table->id();
$table->string('quote');
$table->foreignIdFor(User::class)->nullable();
$table->softDeletes();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('requested_quotes');
}
};

View File

@ -254,7 +254,7 @@ class BaseQuotesSeeder extends Seeder
"It's like a breakfast buffet for a paedophile ",
"Aadyn Goodlet's Handjob Simulatior",
'You threat me with rape all the fucking time',
'I DIDN\"T TRY TO FUCK THE 5 YEAR OLD',
'I DIDN"T TRY TO FUCK THE 5 YEAR OLD',
'I am funny racist',
'Most vegans should go the same way a ginger-haired new babies..... DROWNED, straight to hell, do not pass purgatory, do not collect your last rites',
'Those priest spreads those little boy baby ass cheeks quicker than they can say Amen!!!!!',

View File

@ -1,6 +1,6 @@
<div>
<div class="flex h-16 shrink-0 items-center border-b border-gray-200">
<a href="{{ route('dashboard') }}" wire:navigate>
<a href="{{ route('home') }}" wire:navigate>
<img class="h-12 w-auto" src="https://benjamyn.love/PriceyBot.png" alt="">
</a>
</div>

View File

@ -1,5 +1,9 @@
<x-guest-layout>
<div class="flex flex-col mt-8">
<livewire:pages.quote.request/>
<livewire:pages.quote.requested/>
<livewire:pages.quote.list/>
<livewire:pages.quote.list/>
</div>
</x-guest-layout>

View File

@ -1,11 +1,8 @@
<?php
use App\Models\Quote;
use App\Providers\RouteServiceProvider;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Rule;
use Livewire\Volt\Component;
new #[Layout('layouts.guest')] class extends Component
@ -14,7 +11,7 @@ new #[Layout('layouts.guest')] class extends Component
public function mount(): void
{
$this->quotes = Quote::all()->sortDesc();
$this->quotes = Quote::all()->whereNull('deleted_at')->sortDesc();
}
}; ?>

View File

@ -0,0 +1,40 @@
<?php
use App\Models\Quote;
use App\Models\RequestedQuotes;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Rule;
use Livewire\Volt\Component;
new #[Layout('layouts.guest')] class extends Component
{
#[Rule(['required', 'string', 'unique:requested_quotes,quote'])]
public string $quote = '';
public function store(): void
{
$validated = $this->validate();
RequestedQuotes::create([
'quote' => $validated['quote'],
'user_id' => auth()->user()->id ?? null,
]);
$this->quote = '';
$this->dispatch('quote-requested');
}
}; ?>
<div class="px-4 sm:px-6 lg:px-8">
<form wire:submit="store">
<x-text-input
wire:model="quote"
placeholder="{{ __('What did he say this time?') }}"
class="block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
></x-text-input>
<x-input-error :messages="$errors->get('quote')" class="mt-2"/>
<x-primary-button class="mt-4">{{ __('Request') }}</x-primary-button>
</form>
</div>

View File

@ -0,0 +1,54 @@
<?php
use App\Models\Quote;
use App\Models\RequestedQuotes;
use App\Providers\RouteServiceProvider;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Layout;
use Livewire\Attributes\On;
use Livewire\Attributes\Rule;
use Livewire\Volt\Component;
new #[Layout('layouts.guest')] class extends Component
{
public Collection $quotes;
public function mount(): void
{
$this->getRequestedQuotes();
}
#[On('quote-requested')]
public function getRequestedQuotes()
{
$this->quotes = RequestedQuotes::all()->whereNull('deleted_at')->sortDesc();
}
}; ?>
<div class="px-4 sm:px-6 lg:px-8">
<div class="-mx-4 mt-10 ring-1 ring-gray-300 sm:mx-0 sm:rounded-lg bg-nexi-primary dark:bg-zinc-800 transition-colors duration-300">
<table class="min-w-full divide-y divide-gray-300">
<thead>
<tr>
<th scope="col"
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-nexi-black dark:text-gray-200 sm:pl-6">
Requested Quotes
</th>
{{-- TODO: add logged in user stuff --}}
</tr>
</thead>
<tbody>
@foreach ($quotes as $quote)
<tr>
<td class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
{{ $quote->quote }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>

View File

@ -14,7 +14,8 @@ use Livewire\Volt\Volt;
|
*/
Route::view('/', 'home');
Route::view('/', 'home')
->name('home');
Route::view('dashboard', 'dashboard')
->middleware(['auth'])