Skip to content

Instantly share code, notes, and snippets.

View anthonybudd's full-sized avatar

Anthony C. Budd anthonybudd

View GitHub Profile
<?php
$product = Product::insert([
'weight' => '100'
]);
dd($product->weightInKGs);
<?php
$product = new Product;
dump($product->new);
$product = Product::find(3);
dump($product->new);
$product->color = 'red';
dump($product->dirty);
<?php
$product = Product::find(3);
$product->delete();
<?php
$product = Product::find(1);
dd($product);
<?php
$product = new Product();
$product->color = 'white';
$product->weight = 300;
$product->title = 'the post title';
$product->content = 'the post content';
$product->save();
dump($product);
<?php
$products = Product::in([3, 5, 7]);
dd($products);
<?php
Abstract Class WP_Model implements JsonSerializable{
...
public function isFilterProperty($attribute){
return (
(
isset($this->filter) &&
in_array($attribute, $this->filter) &&
method_exists($this, ('_filter'. ucfirst($attribute)))
<?php
Class Product extends WP_Model{
...
public $filter = [
'weight' => 'intval'
];
}
$product = Product::insert([
'weight' => '250',
]);
<?php
function isAssoc($array){
return count(array_filter(array_keys($array), 'is_string')) > 0;
}
$indexed = [
'apple',
'pear',
'grape'
<?php
Class Product extends WP_Model{
...
public $filter = [
'weight'
];
public function _filterWeight($value){
return intval($value);