GithubHelp home page GithubHelp logo

Comments (6)

robgridley avatar robgridley commented on July 18, 2024

I was able to get form model binding working with my belongs to many and many to many relationships by doing the following:

  1. Eager load the relationships in my controller.
  2. Extend FormBuilder and override one method:
use Illuminate\Database\Eloquent\Collection;
use Collective\Html\FormBuilder as CollectiveFormBuilder;

class FormBuilder extends CollectiveFormBuilder
{
    protected function getModelValueAttribute($name)
    {
        $value = parent::getModelValueAttribute($name);

        return ($value instanceof Collection) ? $value->modelKeys() : $value;
    }

from html.

wiesson avatar wiesson commented on July 18, 2024

@robgridley thanks for sharing your solution! :) 👍

I've extended the Collective as described here: https://laracasts.com/discuss/channels/general-discussion/best-way-to-overwrite-option-method-from-laravel-5-formbuilder-class

from html.

voydz avatar voydz commented on July 18, 2024

👍 thanks for the solution @robgridley , I expect the same behavior as mentioned by @agentphoenix

from html.

agentphoenix avatar agentphoenix commented on July 18, 2024

@adamgoose will this fix (or a similar fix) be merged into the repository or is the expectation that individuals will need to extend the getModelValueAttribute method ourselves to get form model binding working?

from html.

adamgoose avatar adamgoose commented on July 18, 2024

Yes, it was fixed in #45

from html.

agentphoenix avatar agentphoenix commented on July 18, 2024

Awesome! Thanks for fixing this. Huge help! 👍

from html.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.