mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
images
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Livewire\Tables;
|
||||
use App\Models\BookCase;
|
||||
use App\Models\OrangePill;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Livewire\WithFileUploads;
|
||||
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Column;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;
|
||||
@@ -12,10 +13,13 @@ use WireUi\Traits\Actions;
|
||||
|
||||
class BookCaseTable extends DataTableComponent
|
||||
{
|
||||
use WithFileUploads;
|
||||
use Actions;
|
||||
|
||||
public string $country;
|
||||
|
||||
public $photo;
|
||||
|
||||
public bool $viewingModal = false;
|
||||
public $currentModal;
|
||||
public array $orangepill = [
|
||||
@@ -29,7 +33,7 @@ class BookCaseTable extends DataTableComponent
|
||||
{
|
||||
$this->setPrimaryKey('id')
|
||||
->setAdditionalSelects(['id', 'homepage'])
|
||||
->setDefaultSort('orange_pills_count', 'desc')
|
||||
->setDefaultSort('orange_pills_count', 'desc')
|
||||
->setThAttributes(function (Column $column) {
|
||||
return [
|
||||
'class' => 'px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:bg-gray-800 dark:text-gray-400',
|
||||
@@ -97,7 +101,9 @@ class BookCaseTable extends DataTableComponent
|
||||
)
|
||||
->html(),
|
||||
Column::make('Orange-Pilled', 'orange_pilled')
|
||||
->label(fn($row, Column $column) => view('columns.book_cases.oranged-pilled')->withRow($row)->withCountry($this->country))
|
||||
->label(fn($row, Column $column) => view('columns.book_cases.oranged-pilled')
|
||||
->withRow($row)
|
||||
->withCountry($this->country))
|
||||
];
|
||||
}
|
||||
|
||||
@@ -130,6 +136,7 @@ class BookCaseTable extends DataTableComponent
|
||||
$this->validate([
|
||||
'orangepill.amount' => 'required|numeric',
|
||||
'orangepill.date' => 'required|date',
|
||||
'photo' => 'image|max:4096', // 4MB Max
|
||||
]);
|
||||
$orangePill = OrangePill::create([
|
||||
'user_id' => auth()->id(),
|
||||
@@ -137,6 +144,14 @@ class BookCaseTable extends DataTableComponent
|
||||
'amount' => $this->orangepill['amount'],
|
||||
'date' => $this->orangepill['date'],
|
||||
]);
|
||||
$orangePill
|
||||
->addMedia($this->photo)
|
||||
->preservingOriginal()
|
||||
->toMediaCollection('images');
|
||||
$orangePill->load(['media']);
|
||||
$this->currentModal
|
||||
->addMedia($this->photo)
|
||||
->toMediaCollection('images');
|
||||
if ($this->orangepill['comment']) {
|
||||
$this->currentModal->comment($this->orangepill['comment'], null);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,15 @@ use App\Gamify\Points\BookCaseOrangePilled;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
class OrangePill extends Model
|
||||
class OrangePill extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory;
|
||||
use InteractsWithMedia;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -35,6 +40,23 @@ class OrangePill extends Model
|
||||
});
|
||||
}
|
||||
|
||||
public function registerMediaConversions(Media $media = null): void
|
||||
{
|
||||
$this
|
||||
->addMediaConversion('preview')
|
||||
->fit(Manipulations::FIT_CROP, 300, 300)
|
||||
->nonQueued();
|
||||
$this->addMediaConversion('thumb')
|
||||
->fit(Manipulations::FIT_CROP, 130, 130)
|
||||
->width(130)
|
||||
->height(130);
|
||||
}
|
||||
|
||||
public function registerMediaCollections(): void
|
||||
{
|
||||
$this->addMediaCollection('images');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
|
||||
Reference in New Issue
Block a user