Having trouble logging into laravel - php

I'm trying to login. With the Auth::login method, it works but it doesn't keep you logged in.
When I try with this Auth::attempt method, it gives sql error, so I researched the reason is because it is sending JSON and the MariaDB version does not accept it. But I don't know how to get around it
I will briefly explain what the login looks like. You access, enter the email and the recaptcha. Makes a request, checks if the user exists. If it exists, send a code to the email, he types it and falls into the function below to login.
With the Auth::login method, I tried it this way as an example in the documentation.
public function validateCode(Request $request)
{
$email = $request->email;
// Get user
$user = User::whereEmail($email);
if ($user->count() > 0) {
$validateCode = $request->input('validateCode');
// Get code saved in db
$user = $user->first();
$userCode = $user['codConfirm'];
// Check the codes
if ($validateCode == $userCode) {
Auth::login($user, true);
if(Auth::check())
return redirect()->route('home');
else
return redirect()->action('Auth\LoginController#index');
} else {
return view('confirmar-usuario', ['email' => $email]);
}
}
else {
flash('Usuário inválido')->error();
return view('login');
}
}
That way using Auth::attempt, it returns the MariaDB error.
if(Auth::attempt($user)){
...
}
That way it returns null.
I thought this way makes it as I have a hash on the password. But I did a test with another user without a hash in the password and it returns null the same way
if (Auth::attempt(['email' => $user['email'], 'password' => $user['password']])) {
...
}
MariaDB error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '`' at line 1 (SQL: select * from `users` where `*fillable` in (name, email, password, codConfirm, office, people_type, photo, status) and `*hidden` in (remember_token) and `*casts` in (datetime) and `*connection` = mysql and `*table` = users and `*primaryKey` = id and `*keyType` = int and `incrementing` = 1 and 0 = 1 and 0 = 1 and `*perPage` = 15 and `exists` = 1 and `wasRecentlyCreated` = 0 and `*attributes` in (1, Thiago Scomparin, scompa#cantacom.com.br, ?, $2y$10$Fxq0kHJBXLQLCFeDOOtroO5CtFOX38OwwkPlguOJq3bDsOonp37RS, active, ?, 2023-02-16 13:11:19, 2023-02-17 11:15:45, SCpXC2, Escritório Cantacom, Desenvolvedor, users/o5GFWy1woLIni1x0n5J7e0SlOgvsj1y5yyTjznnO.jpg) and `*original` in (1, Thiago Scomparin, scompa#cantacom.com.br, ?, $2y$10$Fxq0kHJBXLQLCFeDOOtroO5CtFOX38OwwkPlguOJq3bDsOonp37RS, active, ?, 2023-02-16 13:11:19, 2023-02-17 11:15:45, SCpXC2, Escritório Cantacom, Desenvolvedor, users/o5GFWy1woLIni1x0n5J7e0SlOgvsj1y5yyTjznnO.jpg) and 0 = 1 and 0 = 1 and 0 = 1 and `*dateFormat` is null and 0 = 1 and 0 = 1 and 0 = 1 and 0 = 1 and 0 = 1 and `timestamps` = 1 and 0 = 1 and `*guarded` in (*) and `*rememberTokenName` = remember_token and `*accessToken` is null limit 1)
Model user
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name',
'email',
'password',
'codConfirm',
'office',
'people_type',
'photo',
'status'
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
// 'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public static function status()
{
return [
'active' => 'Ativo',
'disabled' => 'Desativado'
];
}
}
Auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
],
Some versions
"php": "^7.2.5|^8.0",
"laravel/framework": "^7.29",

Related

User does not stay logged in after Auth:validate was true

i'm trying to develop a multi tenant, app in laravel, with multiple DBs and subdomains, so far i'm using the default user guard for authenticating in the main domain let's say it's example.com, it works fine, i'm also using a different guard for the subdomains, registration works fine, but the login seems to be broken, it authenticates the user but if i try to Auth:user() or even redirect to a protected route it looks like the user has already logged out.
I'm using relational database as the session driver (to avoid subdomains user to modify the cookies domain and access other subdomains), the sessions seems to be stored correctly in the sessions table of the main domain, but in the subdomain every record has the user_id set as null.
Laravel 8.28.1
PHP 7.4.12
Multi tenancy by https://tenancyforlaravel.com
Here is my config/auth.php file
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
// this is the guard for subdomains
'collaboratore' => [
'driver' => 'session',
'provider' => 'collaboratori',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'collaboratori' => [
'driver' => 'eloquent',
'model' => App\Models\Collaboratore::class,
],
this is my model for users in the subdomains
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class Collaboratore extends Authenticatable
{
use HasFactory, Notifiable;
protected $table = 'collaboratore';
protected $guard = 'collaboratore';
public $primaryKey = 'id';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'username',
'password',
'email',
// ... other stuff ...
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
and this is my controller for users in the subdomains
public function login(Request $request )
{
// validate request
$credentials = $this->validate($request, [
'email' => 'required|email',
'password' => 'required'
]);
if ( Auth::guard('collaboratore')->attempt( $credentials ) )
{
// login successful
return redirect('/home');
}
//dd("failed");
// login failed
return $request->expectsJson()
? response([ 'message' => 'Invalid credentials', 401 ])
: redirect()->back()->withInput($request->only('email', 'remember'));
}
any help would be appreciated, i'm kinda stuck right now
From Laravel website https://laravel.com/docs/8.x/authentication#introduction
The attempt method is normally used to handle authentication attempt's
from your application's "login" form. If authentication is successful,
you should regenerate the user's session to prevent session fixation:
if (Auth::attempt($credentials)) {
$request->session()->regenerate();
return redirect()->intended('dashboard');
}
So you should add $request->session()->regenerate(); inside your if attempt.
it looks like i managed to solve his, the problem was here, i changed
public function __construct()
{
$this->middleware('guest')->except('logout');
}
to this
public function __construct()
{
$this->middleware('web');
}
and now it's working, but the session is still note being stored

some data cannot be inserted into database

When new user fills out the registration form and hit submit, i can get all of the data that i need using dd($var). But, while inserting to database laravel says Cannot insert the value NULL into column 'password' . Why laravel didn't get my password while inserting to database ?
i have no idea what i did wrong here.
help me ..
this is my RegisterController.php
protected function create(array $data)
{
$pw_hash = Hash::make($data['Password']);
$uuid4 = Uuid::uuid4();
$a = DB::table('Person.Person')->insert(array(
'PersonId' => $uuid4->toString(),
'PersonName' => $data['PersonName'],
'Email' => $data['Email'],
'IsActive' => false,
'IsLoginActive' => false,
'PasswordSalt' => substr($pw_hash, 7, 22),
'PasswordHash' => sha1($pw_inpt.''.$pw_salt),
'IsMale' => $data['IsMale'],
'Email' => $data['Email'],
'Phone' => $data['Phone'],
'LoginName' => $data['Email'],
'PersonName' => $data["NamaDepan"]." ".$data['NamaBelakang'],
'EmailVerifiedAt' => date('Y-m-d'),
'EmailVerified' => false,
'EmailVerificationCode'=> Hash::make(rand(0,100)),
'password'=> 'aaaapass',
));
dd($a);
}
and this is my User.php Model
class User extends Authenticatable{
use Notifiable;
protected $table = 'Person.Person';
// protected $username = 'Email';
public $incrementing = false;
protected $primaryKey = 'PersonId';
const CREATED_AT = 'CreatedDate';
const UPDATED_AT = 'ModifiedDate';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'PersonId',
'Email',
'Phone',
'IsMale',
'password',
'IsActive',
'Position',
'LoginName',
'kencur',
'ClusterId',
'BirthDate',
'BirthPlace',
'PersonName',
'PersonImage',
'PasswordSalt',
'PasswordHash',
'ModifiedDate',
'IsLoginActive',
'EmailVerified',
'WhatsappNumber',
'EmailVerifiedAt',
'EmailVerificationCode',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password',
'PasswordHash',
'PasswordSalt',
'remember_token',
];
public function getEmailForPasswordReset() {
return $this->Email;
}
}
and this is what laravel says:
Cannot insert the value NULL into column 'password', table 'Assess2.Person.Person'; column does not allow nulls. INSERT fails. (SQL: insert into [Person].[Person] ([PersonId], [PersonName], [Email], [IsActive], [IsLoginActive], [PasswordSalt], [PasswordHash], [IsMale], [Phone], [LoginName], [EmailVerifiedAt], [EmailVerified], [EmailVerificationCode], [password]) values (f6377aeb-df36-4f38-aef5-40c7a2240cc5, has sutenan, namadcvbepan#gmail.com, 0, 0, CTDdYYCXHULY4ad8jQJ9WO, $2y$10$CTDdYYCXHULY4ad8jQJ9WOmVqCILEuJPHSgffLlVW5SK7b7Q4qMpy, true, 55, namadcvbepan#gmail.com, 2019-03-04, 0, $2y$10$vcHlXQgukHomPI.FJZe2XOyl0lJd3Lo5rDqVN5SU8gY3UloPLsr.C, aaaapass))
im using laravel 5.7. thank you
PASSWORD is reserved keyword of database. Try to rename that column.

User passes Auth::attempt(); Fails Auth::check('user')

I'm working with an old copy of a client's database and making the new Laravel app work with its existing users.
I was building and testing with my User model using the 'users' table, but I'm trying to hook it up to the 'auth_user' table. After the changes, my new users are being created correctly. The login is a problem though. The users are passing Auth::attempt($credentials) as expected, but failing when
In my LoginController...
// post to /login
public function login() {
$input = Request::all();
// Log the user in
if (Auth::attempt(['email'=>$input['username'], 'password'=>$input['password']])) {//Auth::attempt(Auth::attempt("admin", ['email' => $input['username'], 'password' => $input['password'], 'active' => 1])) {
// the user is now authenticated.
return Redirect::to('/welcome')->with('message', 'Successfully authenticated');
}
return Redirect::to('/')
->with('message', 'Login Failed: Your Login Credentials Are Invalid');
}
}
I'm definitely passing the Auth::attempt(...), but I don't think my session is being set for that user. After the redirect to /welcome, I fail the Auth::check('user')
public function welcome() {
if (!Auth::check('user')) return Redirect::to('/');
// ... Top secret stuff (no returns or redirects though)
return view('user.welcome', [
'user' => Auth::user()
// ...
]);
}
This redirects back to my login controller.
The kicker is this was all working when I was using my 'users' table instead of 'auth_user'.
Users uses id as the primary key, Auth_user uses 'uid' as the primary key. I'd love to change the uid to be id, but I have to reuse a scary number of MYSQL stored procedures that I can't change.
Relevant models:
User.php:
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
public function rules($scenario = null, $id = null) {
$rules = [];
switch($scenario) {
case 'userAdd':
$rules = [
'password' => 'required|confirmed|min:6'
];
break;
case 'passwordChange':
$rules = [
'password' => 'required|confirmed|min:6'
];
break;
}
return $rules;
}
public function isValid($scenario = null) {
$validation = User::make($this->attributes, User::rules($scenario));
if($validation->passes()) return true;
$this->errors = $validation->messages();
return false;
}
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'auth_user';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = ['username', 'name', 'password', 'email', 'expire', 'active', 'organization','role'];
/**
* The attributes excluded from the model's JSON form.
*
* #var array
*/
protected $hidden = ['password', 'remember_token'];
protected $primaryKey = 'uid';
}
Auth.php (for multiple user types -- I know, I'd rather use roles instead of separate models too)
<?php
return [
'multi' => [
'user' => [
'driver' => 'eloquent',
'model' => App\User::class,
'table' => 'auth_user'
],
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
'table' => 'auth_admin'
]
],
];
I think I covered all my bases for the primary key change, but I can't get the model to pass Auth::check(). Can someone with more Laravel experience illuminate what I'm doing wrong? Thanks in advance!
This is not a complete fix. I still can't find anything to tell Laravel/Guard not to look at the ID column, so I bandaided it by adding an ID column and $user->id = $user->uid;. I'm not proud of this, but it works.
In your User.php Script you need to place this code and this code make the table to login check.
protected $table='auth_users';
In your User.php code place that protected table code in initial stage( after the class function).

How to get login with different database table column name in Laravel 5.2?

I have to implement login functionality in Laravel 5.2. I have successfully done so using the official Laravel documentation except that I do not know how to authenticate the user using different database table column names, namely st_usernameand st_password.
I have searched the Internet for clues but to no avail.
I don't know which class I need to use (like, use Illuminate.......) for Auth. If any one knows the answer, please let me know.
Here is my code:
Login View
#extends('layouts.app')
#section('content')
<div class="contact-bg2">
<div class="container">
<div class="booking">
<h3>Login</h3>
<div class="col-md-4 booking-form" style="margin: 0 33%;">
<form method="post" action="{{ url('/login') }}">
{!! csrf_field() !!}
<h5>USERNAME</h5>
<input type="text" name="username" value="abcuser">
<h5>PASSWORD</h5>
<input type="password" name="password" value="abcpass">
<input type="submit" value="Login">
<input type="reset" value="Reset">
</form>
</div>
</div>
</div>
</div>
<div></div>
#endsection
AuthController
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
$this->username = 'st_username';
$this->password = 'st_password';
}
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
Route File
Route::get('/', function () {
return view('index');
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController#index');
});
config/auth.php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'users' => [
'provider' => 'users',
'email' => 'auth.emails.password',
'table' => 'password_resets',
'expire' => 60,
],
],
];
I searched a lot how to customize Laravel 5.2 authorisation form and this is what is working for me 100%.
Here is from bottom to top solution.
This solution is originally from here: https://laracasts.com/discuss/channels/laravel/replacing-the-laravel-authentication-with-a-custom-authentication
but i had to make couple changes to make it work.
My web app is for the DJs so my custom column names are with 'dj_', for example name is dj_name
config/auth.php
// change this
'driver' => 'eloquent',
// to this
'driver' => 'custom',
in config/app.php add your custom provider to the list
...
'providers' => [
...
// add this on bottom of other providers
App\Providers\CustomAuthProvider::class,
...
],
Create CustomAuthProvider.php inside folder app\Providers
namespace App\Providers;
use Illuminate\Support\Facades\Auth;
use App\Providers\CustomUserProvider;
use Illuminate\Support\ServiceProvider;
class CustomAuthProvider extends ServiceProvider {
/**
* Bootstrap the application services.
*
* #return void
*/
public function boot()
{
Auth::provider('custom', function($app, array $config) {
// Return an instance of Illuminate\Contracts\Auth\UserProvider...
return new CustomUserProvider($app['custom.connection']);
});
}
/**
* Register the application services.
*
* #return void
*/
public function register()
{
//
}
}
Create CustomUserProvider.php also inside folder app\Providers
<?php
namespace App\Providers;
use App\User; use Carbon\Carbon;
use Illuminate\Auth\GenericUser;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
class CustomUserProvider implements UserProvider {
/**
* Retrieve a user by their unique identifier.
*
* #param mixed $identifier
* #return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveById($identifier)
{
// TODO: Implement retrieveById() method.
$qry = User::where('dj_id','=',$identifier);
if($qry->count() >0)
{
$user = $qry->select('dj_id', 'dj_name', 'first_name', 'last_name', 'email', 'password')->first();
$attributes = array(
'id' => $user->dj_id,
'dj_name' => $user->dj_name,
'password' => $user->password,
'email' => $user->email,
'name' => $user->first_name . ' ' . $user->last_name,
);
return $user;
}
return null;
}
/**
* Retrieve a user by by their unique identifier and "remember me" token.
*
* #param mixed $identifier
* #param string $token
* #return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByToken($identifier, $token)
{
// TODO: Implement retrieveByToken() method.
$qry = User::where('dj_id','=',$identifier)->where('remember_token','=',$token);
if($qry->count() >0)
{
$user = $qry->select('dj_id', 'dj_name', 'first_name', 'last_name', 'email', 'password')->first();
$attributes = array(
'id' => $user->dj_id,
'dj_name' => $user->dj_name,
'password' => $user->password,
'email' => $user->email,
'name' => $user->first_name . ' ' . $user->last_name,
);
return $user;
}
return null;
}
/**
* Update the "remember me" token for the given user in storage.
*
* #param \Illuminate\Contracts\Auth\Authenticatable $user
* #param string $token
* #return void
*/
public function updateRememberToken(Authenticatable $user, $token)
{
// TODO: Implement updateRememberToken() method.
$user->setRememberToken($token);
$user->save();
}
/**
* Retrieve a user by the given credentials.
*
* #param array $credentials
* #return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
{
// TODO: Implement retrieveByCredentials() method.
$qry = User::where('email','=',$credentials['email']);
if($qry->count() > 0)
{
$user = $qry->select('dj_id','dj_name','email','password')->first();
return $user;
}
return null;
}
/**
* Validate a user against the given credentials.
*
* #param \Illuminate\Contracts\Auth\Authenticatable $user
* #param array $credentials
* #return bool
*/
public function validateCredentials(Authenticatable $user, array $credentials)
{
// TODO: Implement validateCredentials() method.
// we'll assume if a user was retrieved, it's good
// DIFFERENT THAN ORIGINAL ANSWER
if($user->email == $credentials['email'] && Hash::check($credentials['password'], $user->getAuthPassword()))//$user->getAuthPassword() == md5($credentials['password'].\Config::get('constants.SALT')))
{
//$user->last_login_time = Carbon::now();
$user->save();
return true;
}
return false;
}
}
in App/Http/Controllers/Auth/AuthController.php change all
'name' to 'dj_name' and add your custom fields if you have them...you can also change 'email' to your email column name
In Illuminate\Foundation\Auth\User.php add
protected $table = 'djs';
protected $primaryKey = 'dj_id';
In App/User.php change 'name' to 'dj_name' and add your custom fields.
For changing 'password' column to your custom column name add
public function getAuthPassword(){
return $this->custom_password_column_name;
}
Now backend is all done, so you only have to change layouts login.blade.php, register.blade.php, app.blade.php...here you only have to change 'name' to 'dj_name', email, or your custom fields...
!!! password field NEEDS to stay named password !!!
Also, to make unique email validation change AuthController.php
'custom_email_field' => 'required|email|max:255|unique:users',
to
'custom_email_field' => 'required|email|max:255|unique:custom_table_name',
Also, if you want to make custom created_at an updated_at fields change global variables in Illuminate\Database\Eloquent\Model.php
const CREATED_AT = 'dj_created_at';
const UPDATED_AT = 'dj_updated_at';
A custom Auth::attempt() doesn't work for me by changing the model in auth.php like this:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Person::class,
],
],
If I try to authenticate a Person via custom column names in Auth::attempt:
if (Auth::attempt(['persUsername' => $request->user, 'persPassword' => $request->pass])) {
return redirect()->intended('/');
}
I get the same error:
ErrorException in EloquentUserProvider.php line 112: Undefined index:
password
But I can authenticate a Person like this:
$person = Person
::where('persUsername', $request->user)
->where('persPassword', $request->pass)
->first();
if (! is_null($person)) {
if ($person->persUsername === $request->user && $person->persPassword === $request->pass) {
Auth::login($person, false);
return redirect()->intended('/');
}
}
But that's not the way it should be, I guess.
In the mentioned File (EloquentUserProvider.php), I see 'password' is hardcoded.
public function retrieveByCredentials(array $credentials)
{
$query = $this->createModel()->newQuery();
foreach ($credentials as $key => $value) {
if (! Str::contains($key, 'password')) {
$query->where($key, $value);
}
}
return $query->first();
}
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
So there is actually no way to use a custom column name for passwords the easy way?
This is easy simply use the desired column names in Auth::attempt()/method like so:
if (Auth::attempt(['st_username' =>$username,'st_password' => $password])) {
// Authentication passed...
return redirect()>intended('dashboard');
}
Updated:
If you also wish to change default authentication table which is users by default or change the model name or path App\User by default, you can find these settings in config\auth.php
/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/
//'table' => 'users',
'table' => 'new_tables_for_authentication',
/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/
//'model' => App\User::class,
'model' => App\Models\User::class,

Laravel/Ardent: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters

I'm trying to validate a User using Ardent's validate() method, but I always receive the HY093 error with the following extra information
(SQL: select count(*) as aggregate from:userswhereemail= my.email#gmail.com)
I used Sentry2 for my 'users' table database migration.
I have my User model set up like this:
/**
* Validation Rules for ARDENT here
*/
public static $rules = [
'first_name' => 'required',
'last_name' => 'required',
'email' => 'required|email|unique::users',
'password' => 'required|between:8,32|confirmed',
'password_confirmation' => 'required|between:8,32',
];
/**
* The attributes that can be added to a new User using $user->fill()
*
* #var array
*/
protected $fillable = [
'first_name',
'last_name',
'email',
'password',
'password_confirmation'
];
/**
* Automatically removes _confirmation attributes
*
* #var boolean
*/
public $autoPurgeRedundantAttributes = true;
From a form, I have POST data that includes ['email', 'first_name', 'last_name', 'password', 'password_confirmation] with their respective values that go to the following function in my UserController:
public function signup() {
// Create a new User object
$user = new User();
// Populate attributes with information described in User->fillable
$user->fill( Input::all() );
// Check if info is valid using Ardent's validate() method
if ( $user->validate() ) {
....
....
....
My code always fails on the if ( $user->validate() ) line. Can anyone help me shed some light upon this situation?
The issue was this line
'email' => 'required|email|unique::users'
Should have been
'email' => 'required|email|unique:users'
According to The Laravel Docs

Categories