PHP code example of xtodx / ardent

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

    

xtodx / ardent example snippets


\LaravelArdent\Ardent\Ardent::configureAsExternal(array(
  'driver'    => 'mysql',
  'host'      => 'localhost',
  'port'      => 3306,
  'database'  => 'my_system',
  'username'  => 'myself',
  'password'  => 'h4ckr',
  'charset'   => 'utf8',
  'collation' => 'utf8_unicode_ci'
), 'en'); //English is the default messages language, may be left empty

Route::post('register', function() {
        $rules = array(
            'name'                  => 'word'              => 'ules);

        if ($validator->passes()) {
            User::create(array(
                    'name'     => Request::get('name'),
                    'email'    => Request::get('email'),
                    'password' => Hash::make(Request::get('password'))
                ));

            return Redirect::to('/')->with('message', 'Thanks for registering!');
        } else {
            return Redirect::to('/')->withErrors($validator->getMessages());
        }
    }
);

Route::post('register', function() {
        $user = new User;
        if ($user->save()) {
            return Redirect::to('/')->with('message', 'Thanks for registering!');
        } else {
            return Redirect::to('/')->withErrors($user->errors());
        }
    }
);

use LaravelArdent\Ardent\Ardent;

class User extends Ardent {}

class User extends \LaravelArdent\Ardent\Ardent {
  public static $rules = array(
    'name'                  => 'ed|min:6|confirmed',
    'password_confirmation' => '

$user           = new User;
$user->name     = 'John doe';
$user->email    = '[email protected]';
$user->password = 'test';

$success = $user->save(); // returns false if model is invalid

class User extends \LaravelArdent\Ardent\Ardent {
  public static $customMessages = array(
    '

class User extends \LaravelArdent\Ardent\Ardent {
  public function beforeSave() {
    // if there's a new password, hash it
    if($this->isDirty('password')) {
      $this->password = Hash::make($this->password);
    }
    
    return true;
    //or don't return nothing, since only a boolean false will halt the operation
  }
}

$user->save(array(), array(), array(),
  function ($model) { // closure for beforeSave
    echo "saving the model object...";
    return true;
  },
  function ($model) { // closure for afterSave
    echo "done!";
  }
);

class User extends \LaravelArdent\Ardent\Ardent {
  public static $relationsData = array(
    'address' => array(self::HAS_ONE, 'Address'),
    'orders'  => array(self::HAS_MANY, 'Order'),
    'groups'  => array(self::BELONGS_TO_MANY, 'Group', 'table' => 'groups_have_users')
  );
}

$user = User::find($id);
echo "{$user->address->street}, {$user->address->city} - {$user->address->state}";

$user           = new User;
$user->name     = Request::get('name');
$user->email    = Request::get('email');
$user->password = Hash::make(Request::get('password'));
$user->save();

$user = new User;
$user->save();

class User extends \LaravelArdent\Ardent\Ardent {
  public $autoHydrateEntityFromInput = true;    // hydrates on new entries' validation
  public $forceEntityHydrationFromInput = true; // hydrates whenever validation is called
}

class User extends \LaravelArdent\Ardent\Ardent {
  public $autoPurgeRedundantAttributes = true;
}

function __construct($attributes = array()) {
  parent::__construct($attributes);

  $this->purgeFilters[] = function($key) {
    $purge = array('tempData', 'myAttribute');
    return ! in_array($key, $purge);
  };
}

class User extends \LaravelArdent\Ardent\Ardent {
  public static $passwordAttributes  = array('password');
  public $autoHashPasswordAttributes = true;
}

    'email' => 'unique:users,email,10'

  public static $rules = array(
     'email' => 'med',
     'password_confirmation' => 'between:4,20',
  );

$model->updateUniques();