nova book cases

This commit is contained in:
Benjamin Takats
2022-12-07 19:19:44 +01:00
parent 351c9047a9
commit f79d0e9ff0
9 changed files with 245 additions and 29 deletions

View File

@@ -2,58 +2,63 @@
namespace App\Nova;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\MorphMany;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
class BookCase extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \App\Models\BookCase::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
public static $title = 'title';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id',
'title',
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
ID::make()
->sortable(),
Text::make('Title')
->rules('required', 'string'),
Number::make('Lat')
->rules('required', 'numeric'),
Number::make('Latitude')
->rules('required', 'numeric')
->step(0.000001)
->hideFromIndex(),
Code::make('Lon')
->rules('required', 'json')
->json(),
Number::make('Longitude')
->rules('required', 'numeric')
->step(0.000001)
->hideFromIndex(),
Text::make('Address')
->rules('required', 'string'),
@@ -62,35 +67,47 @@ class BookCase extends Resource
->rules('required', 'string'),
Text::make('Open')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Comment')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Contact')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Bcz')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Boolean::make('Digital')
->rules('required'),
->rules('required')
->hideFromIndex(),
Text::make('Icontype')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Boolean::make('Deactivated')
->rules('required'),
->rules('required'),
Text::make('Deactreason')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Entrytype')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Homepage')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
HasMany::make('OrangePills'),
MorphMany::make('Comments'),
];
}
@@ -99,6 +116,7 @@ class BookCase extends Resource
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function cards(Request $request)
@@ -110,6 +128,7 @@ class BookCase extends Resource
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function filters(Request $request)
@@ -121,6 +140,7 @@ class BookCase extends Resource
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function lenses(Request $request)
@@ -132,6 +152,7 @@ class BookCase extends Resource
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)

53
app/Nova/Comment.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
namespace App\Nova;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Markdown;
use Laravel\Nova\Fields\MorphTo;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Spatie\Comments\Models\Comment as CommentModel;
class Comment extends Resource
{
public static $model = CommentModel::class;
public static $search = [
'id', 'text',
];
public function fields(NovaRequest $request)
{
return [
Text::make('title', function (CommentModel $comment) {
return $comment->topLevel()->commentable?->commentableName() ?? 'Deleted...';
})->readonly(),
MorphTo::make('Commentator')->types([
User::class,
]),
Markdown::make('Original text'),
Text::make('', function (CommentModel $comment) {
if (! $url = $comment?->commentUrl()) {
return '';
}
return "<a target=\"show_comment\" href=\"{$url}\">Show</a>";
})->asHtml(),
Text::make('status', function(CommentModel $comment) {
if ($comment->isApproved()) {
return "<div class='inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-green-100 text-green-800'>Approved</div>";
}
return "<div class='inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800'>Pending</div>";
})->asHtml(),
DateTime::make('Created at'),
];
}
}

View File

@@ -17,6 +17,11 @@ class OrangePill extends Resource
*/
public static $model = \App\Models\OrangePill::class;
public static function label()
{
return 'Inputs';
}
/**
* The single value that should be used to represent the resource when being displayed.
*