Anyone @JeffreyWay
Using form model binding
I'm using form model binding to edit a form, but I have two tables I need to get data for.
One table has username, password, status the other table has
fullname, address, email, phone etc
So how can I use
{{ Form::model($user, ['method' => 'PUT', 'route' => ['profile.update', $user->id], 'class' => 'form-horizontal']) }}
To get all data from the two tables?
From the error it looks like you're not passing the proper model/data to the view. Have you gone through and double checked the code to make sure it's correct?
- Your UserInfo.php model should now be Profile.php with the class name Profile.
Your User model's userInfo() method should now look like this:
public function profile() { return $this->hasOne('Profile', 'user_id'); }Your controller's index method should look like this:
public function index() { $id = Auth::user()->id; $user = User::with('profile')->find($id); // or using the where() method I described above return View::make('account.profile', compact('user')); }
And the call in your view:
{{ Form::text('profile[fullname]', Input::old('profile[fullname]'), array('class'=>'form-control')) }}
Now unless you've changed something else or your tables are structured differently than you originally mentioned, I can guarantee you this works as I set up a test project last night just to try it out.
Please or to participate in this conversation.