Comments (5)
The provided code snippets are for the UserController in Laravel. To resolve this issue, you should ensure that the "username" field is being properly included in the creation and update processes for the user.
Here are the modified sections of code:
In store:
public function store(Request $request)
{
$request->validate([
'photo' => "nullable|mimes:jpg,jpeg,png|max:1024",
'name' => "required|string|max:255",
'username' => "required|unique:users,username",
'email' => "required|unique:users,email",
'bio' => "nullable|max:255",
'status' => "required",
'password' => "required|min:8|max:190",
]);
$user = User::create([
"name" => $request->name,
"username" => $request->username,
"email" => $request->email,
"bio" => $request->bio,
"status" => $request->status,
"password" => Hash::make($request->password),
"email_verified_at" => now(),
]);
$user->syncRoles($request->roles);
$user->syncPermissions($request->permissions);
if (isset($request->photo)) {
$user->updateProfilePhoto($request->photo);
}
Toast::title('User created')->autoDismiss(3);
return redirect()->back();
}
In update:
public function update(Request $request, User $user)
{
$request->validate([
'photo' => "nullable|mimes:jpg,jpeg,png|max:1024",
'name' => "required|string|max:255",
'username' => "required|unique:users,username," . $user->id,
'email' => "required|unique:users,email," . $user->id,
'bio' => "nullable|max:255",
'status' => "required",
'new_password' => "nullable|min:8|max:190",
]);
if (isset($request->photo)) {
$user->updateProfilePhoto($request->photo);
}
$user->forceFill([
'name' => $request->name,
'username' => $request->username,
'email' => $request->email,
'bio' => $request->bio,
'status' => $request->status,
])->save();
if ($request->new_password != null) {
$user->update([
"new_password" => Hash::make($request->new_password)
]);
}
$request->validate([
'roles' => "required|array",
'roles.*' => "required|exists:roles,id",
]);
$user->syncRoles($request->roles);
$user->givePermissionTo($request->permissions);
Toast::title('User updated')->autoDismiss(3);
return redirect()->back();
}
from spladepanel.
You're welcome! I appreciate your effort you've put into making the changes locally. Let's continue collaborating.
from spladepanel.
thank you for your response. I have made the changes in my local i have shared this only to update you.
from spladepanel.
This issue is stale because it has been open for 30 days with no activity.
from spladepanel.
This issue was closed because it has been inactive for 14 days since being marked as stale.
from spladepanel.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spladepanel.