PHP code example of byjesper / laravel-custom-fields
1. Go to this page and download the library: Download byjesper/laravel-custom-fields 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/ */
byjesper / laravel-custom-fields example snippets
Schema::table('contacts', function (Blueprint $table): void {
$table->jsonb('custom_field_values')->default('{}');
});
use Illuminate\Database\Eloquent\Model;
use ByJesper\LaravelCustomFields\Concerns\HasCustomFields;
class Contact extends Model
{
use HasCustomFields;
// Optional override — defaults to the key in custom-fields.entities.models
// protected string $customFieldEntityType = 'contact';
}
$contact->getCustomFieldValues(); // ['phone' => ['value' => '...'], ...]
$contact->getCustomFieldValue('phone'); // '...'
$contact->setCustomFieldValue('phone', '...');
$contact->getCustomFieldDefinitions(); // active definitions for the entity
$contact->validateCustomFields($input); // throws ValidationException