I'm building a user management system...
when I create a user and put an image in 'avatar field' the user will create successfully
but when I let 'avatar field' empty he show me Token and the data that I insert in the field
I already put @csrf
in my form
{
"_token":"f8UnQweYC4xR6WahdsUDlFGoGxyuyzm61rpBEXXXX",
"_method":"post",
"email":"example@abc.xyz",
"name":"example",
"password":"123456789"
}
Store Method
public function store(Request $request)
{
$this->validate($request, array(
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:8',
));
$password = Hash::make($request->password);
$user = new User;
$user->name = $request->input('name');
$user->email = $request->input('email');
$user->password = $password;
$user->roles()->detach();
if ($request['user']) {
$user->roles()->attach(Role::where('name','User')->first());
}
if ($request['editor']) {
$user->roles()->attach(Role::where('name','Editor')->first());
}
if ($request['admin']) {
$user->roles()->attach(Role::where('name','Admin')->first());
}
if($request->hasFile('avatar')){
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save( public_path('/images/avatars/' . $filename ) );
} else {
return $request;
$user->avatar = '';
}
$user->save();
return view('content.admin.user.index');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire