'member_id' => $member,
assuming your column can store 18 characters and it is in the $fillable array
HELLO Everyone I'm trying to give a column in my user table a Str::random(8).time(). value. Here is my code
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'username' => ['required ', 'string' ,'max:255' ,'unique:users'],
// 'package' => ['required'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'member_id' => ['required', 'string', 'max:255'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
*/
protected function create(array $data)
{
dd($data);
$member = Str::random(8).time();
$user = User::create([
'name' => $data['name'],
'username' => $data['username'],
// 'package' => $data['package'],
'email' => $data['email'],
'member_id' => $data[$member],
'password' => Hash::make($data['password']),
]);
return $user;
}
And I didn't forget to add
use Illuminate\Support\Str;
To my controller.
So when I submit my form nothing happens the page just reloads. And I no the problem is from that 'member_id' that I want to allocated Str::random(8).time() to. Please you guys should help me out I'll really be grateful. Thanks
Why is member_id a required input in the validation rules? It is not in the Request, you calculate it in the create method; comment (or remove) that Rule:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'username' => ['required ', 'string' ,'max:255' ,'unique:users'],
// 'package' => ['required'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
// 'member_id' => ['required', 'string', 'max:255'],
]);
}
Please or to participate in this conversation.