Ich versuche, diese Linie zu bekommen $user->profile()->fill($input['profile'])->save();
Laravel 5.1: Aufruf der undefinierten Methode Illuminate Database Abfrage Builder :: fill()
much discussion und failed attempts
ich helfen eine Füllung benötigen Nach arbeiten eloquent Modell
hatte auch einen Probelm mit http://laravel.io/forum/01-06-2016-massassignmentexception-ignoring-fillable-guarded-is-set bewacht, denen ich mit protected $guarded = ['id'];
wand
Profil Modell
public function user(){
return $this->belongsTo('App\User');
}
Benutzermodell
public function profile(){
return $this->hasOne('App\Profile', 'user_id');
}
-Controller
public function update(Request $request, $id)
{
$user = User::with('profile')->findOrFail($id);
$input = $request->all();
if(is_null($user->profile)){
$profile = new Profile($input['profile']);
$user->profile()->save($profile);
alert()->warning('New profile creation attempt!');
}else{
// $user->profile()->fill($input['profile'])->save();
$user->profile->title = $input['profile']['title'];
$user->profile->facebook_username = $input['profile']['facebook_username'];
$user->profile->meetup_user_id = $input['profile']['meetup_user_id'];
$user->profile->save();
// dump($input['profile']['title']);
// dump($user->profile->title);
//Unless it fails silently like before.
alert()->success('Profile Saved!');
}
return redirect()->route('admin.users.edit', [$id]);
}
Beachten Sie, wie ich manuell füllen bin, dann ist dies offensichtlich nicht ideal. this is the result i am trying to achieve
helfen könnte ich meine erste Frage aktualisiert haben. Ihre Antwort würde ein neues Profil erstellen und sieht so aus, als ob das funktionieren würde. Ich versuche jedoch, den vorhandenen Code zu aktualisieren. Danke für Ihre Eingabe –
jetzt, was ist das Problem? Was ist das, was du nicht bekommst? – Qazi
'' 'Aufruf an undefinierte Methode Illuminate \ Database \ Query \ Builder :: fill()' '' bei Zeile '' $ $ user-> profile() -> fill ($ input ['profile']) -> speichern(); '' ' –