PHP code example of malith124 / laravel-ardent-mongodb
1. Go to this page and download the library: Download malith124/laravel-ardent-mongodb 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/ */
malith124 / laravel-ardent-mongodb 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() {
$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 $autoHydrateEntityFromInput = true; // hydrates on new entries' validation
public $forceEntityHydrationFromInput = true; // hydrates whenever validation is called
}
class User extends \LaravelArdent\Ardent\Ardent {
public $autoPurgeRedundantAttributes = true;
}