Controller code:
public function store(UserStoreRequest $request) {
$validated = $request->validated();
$validated['user_type_id'] = 2;
$validated['user_gender_id'] = $request->user_gender_id;
$validated['last_login_at'] = Carbon::now();
$validated['password'] = Hash::make($request->password);
User::create($validated);
return to_route('all-users');
}
Is there a better way to do this?
I tried something like this but didn’t work:
$validated = $request->validated([
'user_type_id' => 2,
'user_gender_id' => $request->user_gender_id,
'last_login_at' => Carbon::now(),
'password' => Hash::make($request->password),
]);
2
Answers
I did like this:
If you store some images do something like this:
there is not official laravel way to do this but you could make most of those values default in a migration.
you could also clean up the controller a little bit by doing something like this.
And then for the default values you can do this in your migration
and then lastly to cast the last_login_at to a now by default you can do that a few ways but using a mutator on the model is probably the best.