<?php
namespace App\Nova;
use Acme\MultilangText\MultilangText;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Http\Requests\NovaRequest;
use Oneduo\NovaFileManager\FileManager;
use Outl1ne\NovaSortable\Traits\HasSortableRows;
class Employee extends Resource
{
use HasSortableRows;
/**
* The model the resource corresponds to.
*
* @var class-string<\App\Models\Employee>
*/
public static $model = \App\Models\Employee::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
// public static $title = 'title';
public function title()
{
// dd($this->title);
// dd(json_decode($this->title)->text);
// dd(Arr::first(json_decode($this->title)->text));
return $this->title && json_decode($this->title)->text ? Arr::first(json_decode($this->title)->text) : $this->id;
}
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id',
'title',
];
public static $trafficCop = false;
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
$countries = \App\Models\Country::query()->get();
$languages = \App\Models\Language::query()->get();
$uploadLink = route('nova.fields.upload.image');
return [
ID::make()->sortable(),
Select::make(__('Type'), 'type')
->options([
'employee' => 'Employee',
'info' => 'Info',
])->hideFromIndex(),
FileManager::make(__('Photo or Icon'), 'image'),
MultilangText::make('Title', 'title')->languages($languages)->countries($countries)->uploadLink($uploadLink)
->fullWidth(),
MultilangText::make('Description', 'description')->languages($languages)->countries($countries)->uploadLink($uploadLink)
->fullWidth()
->hideFromIndex(),
];
}
/**
* Get the cards available for the request.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function cards(NovaRequest $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function filters(NovaRequest $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function lenses(NovaRequest $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function actions(NovaRequest $request)
{
return [];
}
}