book cases added

This commit is contained in:
Benjamin Takats
2022-12-07 14:57:15 +01:00
parent e5b4666d4e
commit ce8f87db6f
59 changed files with 2175 additions and 142 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Http\Livewire\Frontend;
use App\Models\BookCase;
use Livewire\Component;
class CommentBookCase extends Component
{
public string $c = 'de';
public BookCase $bookCase;
public function render()
{
return view('livewire.frontend.comment-book-case');
}
protected function url_to_absolute($url)
{
// Determine request protocol
$request_protocol = $request_protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http');
// If dealing with a Protocol Relative URL
if (stripos($url, '//') === 0) {
return $url;
}
// If dealing with a Root-Relative URL
if (stripos($url, '/') === 0) {
return $request_protocol.'://'.$_SERVER['HTTP_HOST'].$url;
}
// If dealing with an Absolute URL, just return it as-is
if (stripos($url, 'http') === 0) {
return $url;
}
// If dealing with a relative URL,
// and attempt to handle double dot notation ".."
do {
$url = preg_replace('/[^\/]+\/\.\.\//', '', $url, 1, $count);
} while ($count);
// Return the absolute version of a Relative URL
return $request_protocol.'://'.$_SERVER['HTTP_HOST'].'/'.$url;
}
}

View File

@@ -5,10 +5,15 @@ namespace App\Http\Livewire\Tables;
use App\Models\BookCase;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Columns\BooleanColumn;
class BookCaseTable extends DataTableComponent
{
public bool $viewingModal = false;
public $currentModal;
public array $orangepill = [
'amount' => 1,
'date' => null,
];
protected $model = BookCase::class;
public function configure(): void
@@ -22,6 +27,7 @@ class BookCaseTable extends DataTableComponent
];
})
->setTdAttributes(function (Column $column, $row, $columnIndex, $rowIndex) {
return [
'class' => 'px-6 py-4 text-sm font-medium dark:text-white',
'default' => false,
@@ -48,8 +54,8 @@ class BookCaseTable extends DataTableComponent
) => $row->homepage ? '<a target="_blank" class="underline text-amber-500" href="'.$this->url_to_absolute($row->homepage).'">Link</a>' : null
)
->html(),
Column::make('Oranged-Pilled', 'deactivated')
->label(fn($row, Column $column) => view('columns.book_cases.oranged-pilled')->withRow($row)),
Column::make('Orange-Pilled', 'orange_pilled')
->label(fn($row, Column $column) => view('columns.book_cases.oranged-pilled')->withRow($row)),
];
}
@@ -77,4 +83,20 @@ class BookCaseTable extends DataTableComponent
// Return the absolute version of a Relative URL
return $request_protocol.'://'.$_SERVER['HTTP_HOST'].'/'.$url;
}
public function viewHistoryModal($modelId): void
{
$this->viewingModal = true;
$this->currentModal = BookCase::findOrFail($modelId);
}
public function resetModal(): void
{
$this->reset('viewingModal', 'currentModal');
}
public function customView(): string
{
return 'modals.book_cases.orange_pill';
}
}

View File

@@ -4,10 +4,12 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Comments\Models\Concerns\HasComments;
class BookCase extends Model
{
use HasFactory;
use HasComments;
/**
* The attributes that aren't mass assignable.
@@ -28,4 +30,22 @@ class BookCase extends Model
'digital' => 'boolean',
'deactivated' => 'boolean',
];
/*
* This string will be used in notifications on what a new comment
* was made.
*/
public function commentableName(): string
{
//
}
/*
* This URL will be used in notifications to let the user know
* where the comment itself can be read.
*/
public function commentUrl(): string
{
}
}

40
app/Models/OrangePill.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class OrangePill extends Model
{
use HasFactory;
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'user_id' => 'integer',
'book_case_id' => 'integer',
'date' => 'datetime',
];
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class);
}
public function bookCase(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(BookCase::class);
}
}

View File

@@ -10,9 +10,11 @@ use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Comments\Models\Concerns\InteractsWithComments;
use Spatie\Comments\Models\Concerns\Interfaces\CanComment;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements MustVerifyEmail
class User extends Authenticatable implements MustVerifyEmail, CanComment
{
use HasApiTokens;
use HasFactory;
@@ -21,6 +23,7 @@ class User extends Authenticatable implements MustVerifyEmail
use Notifiable;
use TwoFactorAuthenticatable;
use HasRoles;
use InteractsWithComments;
protected $guarded = [];

103
app/Nova/OrangePill.php Normal file
View File

@@ -0,0 +1,103 @@
<?php
namespace App\Nova;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\BelongsTo;
class OrangePill extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \App\Models\OrangePill::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id',
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
DateTime::make('Date')
->rules('required'),
Number::make('Amount')
->rules('required', 'integer'),
BelongsTo::make('User'),
BelongsTo::make('BookCase'),
];
}
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function actions(Request $request)
{
return [];
}
}