Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Laravel form model binding

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 339
    Comment on it

    Form Model Binding is one the important feature in Laravel 4.x. I am reading about this feature from the below link. http://laravel.com/docs/html#form-model-binding

    I have a situation where " The model (User) I want to bind in my form has a separate table for addresses. So I want to be able to fill out the User model's fields, but also the fields for the related Address model. Can I do that with form-model-binding, or do I have to handle the form manually?"

    For solving this problem we don't need any different code in your controller to process this form. All your (named) form variables will be in Input::all().

    The model ($user) you pass in

    Form::model($user, array('route' => array('user.update', $user->id)))
    

    Is just any record you need to, if you have more than one table involved, you'll have to do something like

    $user = User::where('id',$userID)
               ->leftJoin('users_addresses', 'users_addresses.user_id', '=', 'users.id')
               ->first();
    

    In above example User is a model and using above query we will do form model binding using Laravel 4.x

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: