PHP code example of sigep / eloquent-enhancements

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

    

sigep / eloquent-enhancements example snippets


use Sigep\EloquentEnhancements\Traits\Error

setErrors(Illuminate\Support\MessageBag $errors)

errors()

use Sigep\EloquentEnhancements\Traits\SaveAll;

class User extends Eloquent
{
    use Sigep\EloquentEnhancements\Traits\Error;
    use Sigep\EloquentEnhancements\Traits\SaveAll;

    public function phones()
    {
        return $this->hasMany('Phone');
    }
}

class Phone extends Eloquent
{
    public function user()
    {
        return $this->belongsTo('User');
    }
}


$input = array(
    'name' => 'Bob',
    'email' => '[email protected]',
    'phones' => array (
        array('number' => '1111111'),
        array('number' => '2222222'),
    ),
);

$bob = new User();
$bob->createAll($input);

$input = array(
    'name' => 'Bob',
    'email' => '[email protected]',
    'phones' => array (
        array('id' => 1, 'number' => '111-1111'),
        array('id' => 2, 'number' => '222-2222'),
    ),
);

$bob = User::find(1); // assuming bob have the id = 1
$bob->saveAll($input);

$input = array(
    'name' => 'Bob',
    'email' => '[email protected]',
    'phones' => array (
        array('id' => 1, '_delete' => true),
    ),
);

$bob = User::find(1); // assuming bob have the id = 1
$bob->saveAll($input);