1. Go to this page and download the library: Download canvass/canvass-core 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/ */
canvass / canvass-core example snippets
\Canvass\Forge::setFormClosure(static function () {
return new \CanvassLaravel\Model\Form();
});
\Canvass\Forge::setRequestDataClosure(
static function (array $fields = null) {
if (null === $fields) {
return request()->all();
}
return request()->only($fields);
}
);
\Canvass\Forge::setLoggerClosure(static function (\Throwable $e) {
\Log::error($e->getMessage(), [
'file' => $e->getFile(),
'line' => $e->getLine()
]);
});
// Would return new \CanvassLaravel\Model\Form()
$form = \Canvass\Forge::form();
//or
$request_data = \Canvass\Forge::requestData(['label', 'classes']);
namespace App\Canvass\Fields\DatabaseSelect;
use \Canvass\Contract\FieldDataRetrievable;
final class FieldData extends \Canvass\Support\FieldData
implements FieldDataRetrievable
{
/*
* Implementing FieldDataRetrievable::retrieveAdditionalData()
* allows us to pull in any extra data needed before rendering the field.
*/
public function retrieveAdditionalData(): FieldDataRetrievable
{
$field = $this->getField();
$form = $field->getFormModel();
// Get the db rows filtered by this form's owner id
$model = new Retrievable();
$rows = $model->where(
'owner_id',
$form->getData('owner_id')
)->get();
/*
* We'll need to add nested <option> fields to the select
* based on the rows retrieved. So let's loop through the
* rows and create the appropriate data structures.
*/
foreach ($rows as $index => $row) {
$form_field = \Canvass\Forge::field();
$form_field->setFormModel($form);
$data = [
'label' => $row->name,
'value' => $row->id,
'type' => 'option',
'general_type' => 'option',
'sort' => $index + 1,
];
foreach ($data as $key => $value) {
$form_field->setData($key, $value);
}
$form_field->setData('form_id', $field->getData('form_id'));
$form_field->setData('parent_id', $field->getId());
$this->addNestedField($form_field);
}
return $this;
}
}
namespace App\Canvass\Fields\DatabaseSelect;
final class FieldType implements \Canvass\Contract\FieldType
{
public function getType(): string
{
return 'database-select';
}
public function getGeneralType(): string
{
return 'select';
}
}
namespace App\Canvass\Fields\DatabaseSelect;
use Canvass\Contract\FieldData;
use Canvass\Field\AbstractField\AbstractValidateFieldAction;
use Canvass\Support\Validation\Builder;
final class Validate extends AbstractValidateFieldAction
{
protected $attributes_validation_rules = [
'$child['value']);
}
$rules[$field['name']] = [
'field' => $field,
'rules' => $builder->build()
];
}
public function getDataColumnsMatchedWithRequiredBoolean(): array
{
return [
'name' => true,
'label' => true,
'identifier' => true,
'wrap_classes' => false,
'classes' => false,
];
}
public function convertAttributesData($attributes): array
{
$return = [];
if (! empty($attributes['