1. Go to this page and download the library: Download lupennat/conditionals 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/ */
lupennat / conditionals example snippets
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\FormData;
use Laravel\Nova\Fields\Hidden;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Lupennat\Conditionals\Conditional;
class Item extends Resource
{
public function fields(Request $request)
{
return [
Select::make(__('Type'), 'type')->options([
'boolean' => 'Boolean',
'number' => 'Number',
'not-exists' => 'No Value',
'text' => 'Text'
]),
Conditional::make(__('Value'))
->dependsOn(['type'], function (Conditional $field, NovaRequest $novaRequest, FormData $formData) {
return match ($formData->type) {
'boolean' => Boolean::make(__('Value'), 'value')->rules('
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\FormData;
use Laravel\Nova\Fields\Hidden;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Lupennat\Conditionals\ConditionalMany;
class ItemList extends Resource
{
public function fields(Request $request)
{
return [
ID::make()->sortable(),
ConditionalMany::make('Item Value', 'items')
->each(
function ($item) {
return match ($item->type) {
'boolean' => Boolean::make(__('Value'), 'value')
'number' => Number::make(__('Value'), 'value'),
'text' => Text::make(__('Value'), 'value'),
default => Hidden::make(__('Value'), 'value')
}
}
)
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.