for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Webfactor\Laravel\Generators\Traits;
trait CrudField
{
private $field = [];
protected $crudFieldType;
protected $crudFieldOptions = [];
public function getCrudField(): array
$this->field['name'] = $this->name;
name
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->field['label'] = $this->name;
$this->field['type'] = $this->crudFieldType;
if ($this->crudFieldOptions) {
$this->addCrudFieldOptions();
}
return $this->field;
private function addCrudFieldOptions()
foreach ($this->crudFieldOptions as $key => $option) {
$this->field[$key] = $option;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: