i have this two related table :
Users --> id | username | password | ...
Users_profiles --> id | user_id | firstname | lastname | ...
My User Eloquent is :
class User extends Authenticatable
{
protected $fillable = ['username','password','status','type'];
protected $hidden = [
'password', 'remember_token',
];
public function profile()
{
return $this->hasOne('App\User_profile','user_id', 'id');
}
}
My User Controller is :
public function Update($id, Request $r){
$rules = [
'username' => 'unique:users,username',
'firstname' => 'required',
'lastname' => 'required',
'mobile' => 'required',
];
$validator = \Validator::make($r->all(), $rules);
if ($validator->fails()) {
return response()->json(['status' => 'failed', 'message' => $validator->errors()->first()]);
} else {
$users = User::with('profile')->where('id',$id)->first();
$users->username = $r->username;
$users->profile->firstname = $r->firstname;
$users->push();
return response()->json(['status' => 'success', 'message' => "OK"]);
}
}
But now when i try to update my record in first it takes long time (about 1 min) and then after update users.username and without changes any thing on users_profile table, appears white screen.
also save() method has this results again.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire