1. Go to this page and download the library: Download think.studio/nova-thinkit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
think.studio / nova-thinkit example snippets
public function actions(NovaRequest $request)
{
return [
(new \NovaThinKit\Nova\Actions\LoginToDifferentGuard(
route('dashboard.overview'),
'owners_web',
__('Login to owner dashboard'),
__('Are you sure you want to continue?'),
))
// optional callback how to find correct user
->findIdUsing(fn (Contact $model) => Owner::query()->where('contact_id', $model->getKey())->first()?->getKey())
// other default method actions...
->canRun(fn ($request, Contact $model) => $model->role === "owner"),
];
}
use NovaThinKit\Nova\Actions\LoginToDifferentGuard;
public function actions(NovaRequest $request)
{
return [
( \NovaThinKit\Nova\Actions\SendResetPasswordEmail::make('contacts', __('Send reset password'), __('Are you sure you want to continue?')))
// optional callback how to find correct user
->findIdUsing(fn (Contact $model) => Owner::query()->where('contact_id', $model->getKey())->first()?->getKey())
// other default method actions...
->canRun(fn ($request, Contact $model) => $model->role === "owner"),
];
}
\NovaThinKit\Nova\Filters\DynamicBooleanFilter::make([
'Active' => 'active',
'Paused' => 'paused',
] /* options */, 'status' /* column to filter */, 'Status' /* title */),
// Useful with HumanReadable enums:
\NovaThinKit\Nova\Filters\DynamicBooleanFilter::make(array_flip(CompanyStatus::options()), 'status', 'Status'),
use NovaThinKit\Nova\Filters\BelongsToFilter;
public function filters(NovaRequest $request)
{
return [
// type - this is belongsTo() relation method name
new BelongsToFilter('type'),
// or
(new BelongsToFilter('type'))->setTitleKeyName('title'),
// or
(new BelongsToFilter('type'))->setFilterName('Filter by type'),
];
}
public function filters(NovaRequest $request)
{
return [
\NovaThinKit\Nova\Filters\BelongsToManyFilter::make('tags')
->setTitleKeyName('name' /* label key name */)
->setFilterName('By tag'),
];
}
public function fields(NovaRequest $request)
{
$metaFieldUpdater = new \NovaThinKit\Nova\Helpers\MetaFieldUpdater(
'metaData' /* hasMany relation method name */,
'key' /* key name in neta table */,
'value' /* data name in neta table */
);
return [
$metaFieldUpdater->field(
Select::make('University', 'university')->options(University::options())
),
// ALso works with flexible
$metaFieldUpdater->field(
Flexible::make('Ethos list', 'cf-numeric_list_with_team')
->limit(20)
->useLayout(EthosItemLayout::class),
),
];
}
class Page extends Resource
{
use \NovaThinKit\FeatureImage\Nova\HasFeatureImage;
// ... other methods
public function fields(NovaRequest $request)
{
return [
// other fields
$this->fieldFeatureImage(),
];
}
}
namespace App\Nova\ResourceTemplates\Pages;
use NovaThinKit\Nova\Helpers\MetaFieldUpdater;
use NovaThinKit\Nova\ResourceTemplates\ResourceTemplate;
class HomePageTemplate extends ResourceTemplate
{
public function fields(NovaRequest $request): array
{
$metaUpdater = new MetaFieldUpdater('meta', 'key', 'value');
return [
Text::make('Some Custom text', 'some_custom_text')
->hideWhenCreating()
->hideFromIndex()
->showOnPreview(),
$metaUpdater->field(
Text::make('Custom text', 'custom_text')
->hideWhenCreating()
->hideFromIndex()
->showOnPreview(),
),
];
}
}
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
\NovaThinKit\Nova\ResourceTemplates\TemplateFinder::templatesMap(Page::class, [
'home' => HomePageTemplate::class,
'contact' => ContactPageTemplate::class,
]);
}
}
class Page extends Resource
{
use \NovaThinKit\Nova\ResourceTemplates\HasTemplate;
public function fields(NovaRequest $request)
{
return [
ID::make()->sortable(),
...$this->templateFields($request),
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.