Can you help me ? i want change password type from varchar to md5
code:
$data = array(
'email' => $this->input->post('email') ,
'password' => $this->input->post('password')
);
Instead of md5 use password hashing. php has built in function.
password_hash(string,PASSWORD_BCRYPT);
to verify it.
use password verify method.
passord_verify($password,$hashed_password);
In your case you can do
$data = array(
'email' => $this->input->post('email') ,
'password' => password_hash($this->input->post('password'),PASSWORD_BCRYPT)
);
Make sure database column has appropriate char length. if its string type then its not problem.
Related
Hello i am new to Laravel so currently im doing a CRUD. I have created this insert function that works well except one value is never inserted. This is the code below:
public function storeClient(Request $request) {
$request->validate([
'name' => 'required',
'email' => 'required|email',
'phone' => 'nullable',
'age'=>'required',
]);
Client::create($request->all());
dd($request->phone);
return redirect('/')->with('msg', 'Client Saved successfully!.');
}
the phone' => 'nullable', value will not insert in the database unless i update the existing values. I tried this command dd($request->phone); and it shows the correct value from the user input. Any idea why the value will be inserted as null on database?
This is the value output when i make the dd command
I tried this other code which works well but im trying to use the default create() function of laravel. This is the other code i did that works well:
public function storeClient()
{
$client = new Client();
$client->name = request('name');
$client->email = request('email');
$client->phone_number = request('phone');
$client->age = request('age');
$client->save();
return redirect('/')->with('msg','Client Saved successfully!');
}
first i did not like nullable here 'phone' => 'nullable',
then u should see what do you register in your Client table phone_number or phone,
$client->phone_number = request('phone');
i think you should rename your input name phone to phone_number and will work
When you are trying to use default create method the fields names must be same as in database.
$client->phone_number = request('phone');
this line works due to the name you entered manually.
to work with default create method change the name of field in database as phone.
I have tried implementing first name and last name of the person trying to authenticate from facebook. I have seen lots of tutorials and followed them accordingly but couldn't get it.
I have tried
$user = Member::create([
'first_name'=> $providerUser->getFirstName(),
'last_name'=>$providerUser->getLastName(),
'email' => $providerUser->getEmail(),
'profilepic'=>$providerUser->getAvatar(),
'password' => md5(rand(1,10000)),
]);
I assumed the provider you use is socialite, to get last name ans first name you can use $providerUser->user['first_name'] and $providerUser->user['last_name']
So based your code:
$user = Member::create([
'first_name'=> $providerUser->user['first_name'],
'last_name'=>$providerUser->user['last_name'],
'email' => $providerUser->getEmail(),
'profilepic'=>$providerUser->getAvatar(),
'password' => md5(rand(1,10000)),
]);
I have a Model which contains many foreign keys. One of those foreign keys must be a unique value.
My validation rules are the following ones:
$data['rules'] = [
'address' => 'required|string',
'buyer_id' => 'required|exists:buyers,id',
'buyer_name' => 'required|string',
'date' => 'required|date',
'email' => 'required|email',
'identification_photo' => 'required|string',
'invoice' => 'string|required',
'middleman_id' => 'nullable|exists:middlemen,id',
'price' => 'required|numeric|between:1,99999999999999999999999999.9999',
'property_id' => 'required|exists:properties,id|unique:reservations,property_id',
'purchase_receipt' => 'required|string',
'rfc' => array(
'required',
'regex:/^([A-Z,Ñ,&]{3,4}([0-9]{2})(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])[A-Z|\d]{3})$/'
),
'tier_id' => 'nullable|exists:tiers,id',
'user_id' => 'required|exists:users,id',
];
The one that I have trouble is property_id. This must be unique in the current table which is reservations.
In order to ignore that validation when I make an update, I'm adding this line of code before calling the Validator:
$book['rules']['property_id'] .= ",{$item->property_id}";
And when I do a Log::info of all my rules, I got the following line: 'property_id' => 'required|exists:properties,id|unique:reservations,property_id,4',
But I keep receiving the error. Am I doing something wrong?
The error is on this line:
$book['rules']['property_id'] .= ",{$item->property_id}";
Instead of passing the id of the foreign key you want to ignore, you have to give the current model ID in order to ignore that validation for a specific item.
$book['rules']['property_id'] .= ",{$item->id}";
With this you tell that for your Model with id = x, ignore that specific validation. To understand it in a better way, you are telling that for this validation, ignore the validation of the property only for the record with id equals to the $item->id.
I think the line of code you are looking for is
'property_id' => 'required|exists:properties,id|unique:reservations,property_id,'.$request->id',
This ignores the current row you are updating while also validating your property_id
I've got a login form and I'm using Tank Auth for form validation, etc. For the form, I'm not using labels; instead I am populating the value field to tell users what to input (e.g., Email Address in the "email" field). But Tank Auth presets the value with a set_value function:
$login = array(
'name' => 'login',
'id' => 'login',
'value' => set_value('login'),
);
Is there any way to keep the set_value function, but also enter a value that can be used in place of a label? Or is there some other way to get users to see the instructional text without getting rid of the set_value function?
You are able to set a second argument for set_value().
For example, you could write this:
$login = array(
'name' => 'login',
'id' => 'login',
'value' => set_value('login', 'You\'re username'),
);
To set the preset value (if nothing else has been entered) to You're username
I am trying to add an entry to an Oracle table which has a date field. So far, I've only been able to do it like this:
$createdDate = $entry->createdDate->toString('yyyy-MM-dd');
$data = array(
'ID' => $entry->id,
'STATE' => $entry->state,
'CREATED_DATE' => new Zend_Db_Expr("to_date('$createdDate', 'YYYY-MM-DD')")
);
$this->_getGateway()->insert($data);
Is there a better way? This solution smells dirty to me.
You should be able to do this instead:
$createdDate = $entry->createdDate->toString('yyyy-MM-dd');
$data = array(
'ID' => $entry->id,
'STATE' => $entry->state,
'CREATED_DATE' => new Zend_Db_Expr("date '$createdDate'")
);
$this->_getGateway()->insert($data);
The only difference is the use of an ANSI date literal in line 5.