PHP code example of rtfmfm / uniquewith-validator
1. Go to this page and download the library: Download rtfmfm/uniquewith-validator 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/ */
rtfmfm / uniquewith-validator example snippets
'providers' => [
// ...
Rtfmfm\UniqueWithValidator\ServiceProvider::class,
],
$rules = [
'<field1>' => 'unique_with:<table>,<field2>[,<field3>,...,<ignore_rowid>]',
];
$rules = [
'first_name' => 'unique_with:users, middle_name, last_name = sur_name',
];
$rules = [
'first_name' => '];
$rules = [
'first_name' => '];
$rules = [
'first_name' => '];
$rules = [
'first_name' => '];
protected function validationData()
{
return array_merge($this->request->all(), [
'deleted_at' => null
]);
}
$rules = [
'first_name' => 'unique_with:some-database.users, middle_name, last_name',
];
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('first_name');
$table->string('last_name');
$table->unique(['first_name', 'last_name']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
class User extends Eloquent { }
Route::post('test', function() {
$rules = [
'first_name' => 'ake(Input::all(), $rules);
if($validator->fails()) {
return Redirect::back()->withErrors($validator);
}
$user = new User;
$user->first_name = Input::get('first_name');
$user->last_name = Input::get('last_name');
$user->save();
return Redirect::home()->with('success', 'User created!');
});