1. Go to this page and download the library: Download hxm/extrafield 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/ */
hxm / extrafield example snippets
function boot()
{
\HXM\ExtraField\ExtraField::$ignoreMigration = true;
}
use HXM\ExtraField\Contracts\CanMakeExtraFieldInterface;
use HXM\ExtraField\Traits\HasExtraField;
class AnyModel extends Model implements CanMakeExtraFieldInterface
{
use HasExtraField;
}
use HXM\ExtraField\Contracts\CanMakeExtraFieldByInstanceInterface;
use HXM\ExtraField\Traits\HasExtraFieldByInstance;
class AnyModel extends Model implements CanMakeExtraFieldByInstanceInterface
{
use HasExtraFieldByInstance;
}
use HXM\ExtraField\Contracts\CanMakeExtraFieldInterface;
use HXM\ExtraField\Traits\HasExtraField;
class ParentModel extends Model implements CanMakeExtraFieldInterface
{
use HasExtraField;
public function type()
{
return $this->belongsTo(AnyModel::class);
}
public function getExtraFieldTargetTypeInstance(): CanMakeExtraFieldInterface
{
return $this->type;
}
}
...
use HXM\ExtraField\Actions\UpdateOrCreateFieldAction;
use Illuminate\Http\Request;
use AnyModel;
class Controller ...
{
function createOrUpdateExtraField(AnyModel $modelHasExtraField, Request $request, UpdateOrCreateFieldAction $action)
{
$action->handle($modelHasExtraField, $request, $allowMissingFields);
}
}
use HXM\ExtraField\Contracts\CanMakeExtraFieldByInstanceInterface;
use HXM\ExtraField\Traits\HasExtraFieldByInstance;
use HXM\ExtraField\Contracts\CanAccessExtraFieldValueInterface;
use HXM\ExtraField\Traits\HasExtraFieldValue;
use HXM\ExtraField\Traits\AutoValidationAndSaveExtraFieldValue;
class AnyModel extends Model implements CanMakeExtraFieldByInstanceInterface, CanAccessExtraFieldValueInterface
{
use HasExtraFieldByInstance;
use HasExtraFieldValue;
// use AutoValidationAndSaveExtraFieldValue;
// Automatically save Extra Values when model saved
}
use HXM\ExtraField\Contracts\CanMakeExtraFieldInterface;
use HXM\ExtraField\Contracts\CanAccessExtraFieldValueInterface;
use HXM\ExtraField\Traits\HasExtraFieldValue;
use HXM\ExtraField\Traits\AutoValidationAndSaveExtraFieldValue;
class ParentModel extends Model implements CanAccessExtraFieldValueInterface
{
use HasExtraFieldValue;
// use AutoValidationAndSaveExtraFieldValue;
// Automatically save Extra Values when model saved
public function type()
{
return $this->belongsTo(AnyModel::class);
}
public function getExtraFieldTargetTypeInstance(): CanMakeExtraFieldInterface
{
return $this->type;
}
}
...
use HXM\ExtraField\ExtraFieldValueValidation;
use HXM\ExtraField\Actions\SaveExtraFieldValueForTargetAction;
use Illuminate\Http\Request;
use AnyModel;
class Controller ...
{
function store(Request $request, SaveExtraFieldValueForTargetAction $action)
{
$model = AnyModel::create([
...
]);
$validation = new ExtraFieldValueValidation($model, $request->all());
$action->handle($model, $validation);
}
}