PHP code example of mookofe / laravel-support

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

    

mookofe / laravel-support example snippets


 namespace App;

use Mookofe\LaravelSupport\Model;

class User extends Model {

}


    $model->current_date = '2015-01-01 00:00:00';
    echo $model->getHumanDate('current_date');                 //January 01, 2015
        
    //Using Carbon datetime format:
    $format = 'l jS \\of F Y h:i:s A';
    echo $model->getHumanDate('current_date', $format);        //Thursday 1st of January 01 2015 00:00:00 AM


    $model = new Model;
    echo $model->attributeExist('new_property');          //false
    
    $model->new_property = null;
    echo $model->attributeExist('new_property');          //true

    $model = new Model;
    $changes = $model->getChanges();                    //array();
    
    $model->client_id = 1;
    $changes = $model->getChanges();                    //array( array('field' => 'client_id', 'old_value' => '', 'new_value' => 1) );

    $model = new Model;
    $model->client_id = 1;
    $model->amount = 100;
    $model->date = Carbon::now();
    
    $new_model_fields = array('client_id', 'amount');
    $new_model = $model->extract($new_model_fields);
    
    //You are also allowed to change property name:
    $new_model_fields = array('new_field' => 'client_id', 'amount');
    $new_model = $model->extract($new_model_fields);

    $fields_to_remove = array('client_id', 'amount');
    $model->removeFields($fields_to_remove);

    $collection = User::all();
    
    //New collection only with the specified fields
    $format = array('name', 'lastname');
    $new_collection = $collection->rebuild($format);
    
    //You can also change field names and objects as follow:
    $format = array('id', 'personal_data' => ['name', 'lastname', 'sex']);
    $new_collection = $collection->rebuild($format);

    $collection = User::all();
    $user_avatar_collection = User_avatar::all();
        
    //Check if all users have a record on the user avatar collection
    $collection->compare($user_avatar_collection, 'user_id', 'id');        //boolean

    $collection = User::all();
    $empty_collection = $collection->createNewInstance();

    $collection = Post::all();
    $latests = $collection->getLatestsByField( array('user_id', 'post_category_id') );

    $collection = Post::all();
    $first = $collection->getFirstByField( array('user_id', 'post_category_id') );

    $collection = Product::all();
    $sum = $collection->sumValues('product_category_id', 10, 'price');

    $collection = Product::all();
    $filter = array('product_category_id' => 10, 'price' => 100);
    
    $filtered = $collection->findByFields($filter);

    $users = User::all();
    $user_avatar = User_avatar::all()
    
    $fields_to_compare = array('id' => 'user_id');
    $fields_to_merge = array('file_path');
    
    $users->mergeByFields($user_avatar, $fields_to_compare, $fields_to_merge);

    $users = User::all();
    $filter = array('name' => 'John');
    $options = array(
        'found_text' => 'Item exist',
        'not_found_text' => 'Item not found',
        'field' => 'field_name'
    );
        
    echo $users->showIfFound($filter, $options);

    $user_comments = User_comment::all();
    $user_comments->delete();

    $products = Product::all();
    echo $products->avg('price');
    
    //Including null values for average, assumed as zero.
    echo $products->avg('price', true);

    $collection = Product::all();
    $filter = array('product_category_id' => 10);
    
    $filtered = $collection->findIfDifferent($filter);

    $users = User::all();
    $max_user = $users->maxItem('id');

    $users = User::all();    
    $flat_users = $users->toFlatArray('id');
    
    var_dump($flat_users);						// array(1,2,3)


$ php composer install
batch
$ php composer update