The Column attribute allows you to customize the column name of your model's public properties. In the example below the product_name property will be mapped to the name column on the database table:
useIlluminate\Database\Eloquent\Model;useWendellAdriel\Lift\Attributes\Column;useWendellAdriel\Lift\Attributes\Fillable;useWendellAdriel\Lift\Attributes\PrimaryKey;useWendellAdriel\Lift\Attributes\Rules;useWendellAdriel\Lift\Lift;finalclassProductextendsModel{useLift; #[PrimaryKey]publicint $id; #[Rules(['required','string'], ['required'=>'The Product name can not be empty'])] #[Fillable] #[Column('name')]publicstring $product_name;}
You can also set a default value for your public properties using the Column attribute. In the example below the price property will be mapped to the price column on the database table and will have a default value of 0.0:
useIlluminate\Database\Eloquent\Model;useWendellAdriel\Lift\Attributes\Cast;useWendellAdriel\Lift\Attributes\Column;useWendellAdriel\Lift\Attributes\Fillable;useWendellAdriel\Lift\Attributes\PrimaryKey;useWendellAdriel\Lift\Attributes\Rules;useWendellAdriel\Lift\Lift;finalclassProductextendsModel{useLift; #[PrimaryKey]publicint $id; #[Rules(['required','string'], ['required'=>'The Product name can not be empty'])] #[Fillable] #[Column('name')]publicstring $product_name; #[Column(default:0.0)] #[Cast('float')]publicfloat $price;}
You can also set a default value for your public properties by passing a function name as the default value:
useIlluminate\Database\Eloquent\Model;useWendellAdriel\Lift\Attributes\Cast;useWendellAdriel\Lift\Attributes\Column;useWendellAdriel\Lift\Attributes\Fillable;useWendellAdriel\Lift\Attributes\PrimaryKey;useWendellAdriel\Lift\Attributes\Rules;useWendellAdriel\Lift\Lift;finalclassProductextendsModel{useLift; #[PrimaryKey]publicint $id; #[Rules(['required','string'], ['required'=>'The Product name can not be empty'])] #[Fillable] #[Column('name')]publicstring $product_name; #[Column(default:0.0)] #[Cast('float')]publicfloat $price; #[Column(default:'generatePromotionalPrice')] #[Cast('float')]publicfloat $promotional_price;publicfunctiongeneratePromotionalPrice():float {return$this->price *0.8; }}