1. Go to this page and download the library: Download inspheric/nova-defaultable 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/ */
inspheric / nova-defaultable example snippets
use Inspheric\NovaDefaultable\HasDefaultableFields;
abstract class Resource extends NovaResource
{
use HasDefaultableFields;
// ...
}
use Inspheric\NovaDefaultable\HasDefaultableActionFields;
class YourAction extends Action
{
use HasDefaultableActionFields;
// ...
}
Text::make('Name')
->default('Default Name'),
Boolean::make('Active')
->default(true),
Text::make('Name')
->default(function(NovaRequest $request) {
return $request->user()->name.'\'s New Resource';
}),
class YourAction extends Action
{
protected $refreshIndex = true;
public function handle(ActionFields $fields, Collection $models)
{
// ...
}
}
$lastInvoiceNumber = auth()->user()->last_invoice_number;
Number::make('Invoice Number')
->default($lastInvoiceNumber, function($value, NovaRequest $request) {
return $value + 1; // Note: Here the $value came from $lastInvoiceNumber
}),
Number::make('Invoice Number')
->defaultLast(function($value, NovaRequest $request) {
return $value + 1; // Note: Here the $value came from the cache
}),
use Inspheric\NovaDefault\DefaultableField;
DefaultableField::extend(YourField::class, function($field, $value) {
return $field->withMeta([
'value' => $value, // This line is usually