PHP code example of aquanode / formation

1. Go to this page and download the library: Download aquanode/formation 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/ */

    

aquanode / formation example snippets


$defaults = [
	'name'   => 'Ron Paul',
	'email'  => '[email protected]',
	'active' => true,
];

Form::setDefaults($defaults);

$user = User::find(1);

Form::setDefaults($user, ['posts']);

$user = User::find(1);

Form::setDefaults($user, [
	'posts' => '*',
	'roles' => 'id',
]);

$rules = [
	'user.name' => [' 'email']
];

Form::setValidationRules($rules);

if (Form::isValid())
{
	return true;
}

if (Form::isValid('user')) // validates array fields with names like "user[name]" and "user[email]"
{
	return true;
}

if (Form::isValid('user.')) // ending with a "." allows us to validate fields like "user[0][name]" and "user[1][name]"
{
	return true;
}

$labels = [
	'name'  =>  'Name',
	'email' => 'Email Address',
];

Form::setLabels($labels);

 $checkboxes = simple_options(['Rain', 'Thunder', 'Lightning']); 

 $checkboxes = [
	'checkbox_name'  => 'Checkbox Label!',
	'checkbox_name2' => 'Checkbox Label 2!',
]; 

$user = App\Models\User\User::find(1);

Form::setDefaults($user, [
	'roles' => 'id',
]);

$roleOptions = prep_options(App\Models\User\Role::get(), ['id', 'name']);

 // you may pass either a "selected" or "value" attribute to select an option 

 // display options from 0 to 180 incrementing by 10 each time 

 // count up 12 months from current month 

 // count down 12 months from current month 

 // count up to a specific month from current month 

 // count down to a specific month from another specific month 

 // count down 12 months from current month and use the last day of the month for "month_end" field 

 $options = simple_options(['T-Rex', 'Parasaurolophus', 'Triceratops']); 

 $options = simple_options(['T-Rex', 'Parasaurolophus', 'Triceratops']); 

$attributes = [
	'class'       => 'select-number',
	'options'     => number_options(1, 10),
	'null-option' => 'Select a Number',
	'value'       => 3,
];

protected static $arrayIncludedMethods = [
	'name' => 'getName(true)',
	'url'  => 'getUrl', // parameters not 

	/**
	 * The attribute sets for the model.
	 *
	 * @var array
	 */
	protected static $attributeSets = [
		'standard' => [
			'id',
			'content',
			'url', // this could even be a key listed in $arrayIncludedMethods for a getUrl() method
		],

		'update' => [
			'set:standard', // t:author', // this will use an attribute set from the model used for the "author" relationship
			'section' => 'class:'.Section::class, // this will look for an attribute set called "standard"
			'tags'    => 'class:'.Tag::class.';set', // this will look for an attribute set called "set"
		],
	];

	/**
	 * The methods to automatically atic $attributeSets = [
		'author' => [
			'id',
			'username',
			'select:first_name', // this data is only being selected, and will be combined using the "getName" method defined above
			'select:last_name', // this data is only being selected, and will be combined using the "getName" method defined above
			'name',
		],
	];

	/**
	 * The attribute sets for the model.
	 *
	 * @var array
	 */
	protected static $arrayIncludedMethods = [
		'name' => 'getName',
	];


	/**
	 * The data transforming configuration.
	 *
	 * @var array
	 */
	public static $transformConfig = [
		'arrayIncludedMethods' => [
			//
		],

		'attributeSets' => [
			'standard' => [
				//
			],
		],

		'relatedAttributeSets' => [
			'standard' => [
				//
			],
		],
	];

	$post = Post::selectAttributeSet('standard')
		->limitRelatedData()
		->first();

	// selectSet is short-hand alias for selectAttributeSet
	$users = User::selectSet('author', true), passing true as the second parameter automatically calls limitRelatedData() scope
		->get()
		->toArray();

	return $post->toArray('standard');

	return $post->toLimitedArray(); // same as above, assumes "standard" by default

	return Post::orderBy('id')->get()->toArray('standard'); // filter models in a collection with attribute set

	return Post::orderBy('id')->paginate(25)->toArray('standard'); // return a paginator converted to an array

	return Post::orderBy('id')->setPage(3)->paginate(25)->collectionToArray('standard'); // return just the collection

	/**
	 * The special formatted fields for the model for saving to the database.
	 *
	 * @var array
	 */
	protected static $formatsForDb = [
		'media_type'   => 'null-if-false:media',
		'published_at' => 'null-if-false:published',
	];

// new record
Form::setValidationRulesForNew($input);

// existing record
$record->setValidationRules($input);

// new or existing record ($record can be null)
Form::setValidationRulesForModel($record, $input);