Coder Social home page Coder Social logo

Comments (5)

bakerkretzmar avatar bakerkretzmar commented on May 22, 2024 7

Just wanted to share that I had the same question and I'm pretty sure I have it working. Laravel 5.8 added model events for pivot table models, so that event does fire now.

@esl51 it looks like you just didn't create the order_column column on your pivot table in the DB. This should work:

class CreateQuestionnaireAttributeTable extends Migration
{
    public function up()
    {
        Schema::create('questionnaire_attribute', function (Blueprint $table) {
            // ...
            $table->integer('order_column');
        });
    }
}

class Questionnaire extends Model
{
    public function attributes()
    {
        return $this->belongsToMany(Attribute::class, 'questionnaire_attribute')
                    ->using(QuestionnaireAttribute::class);
    }
}

class Attribute extends Model
{
    public function questionnaires()
    {
        return $this->belongsToMany(Questionnaire::class, 'questionnaire_attribute')
                    ->using(QuestionnaireAttribute::class);
    }
}

class QuestionnaireAttribute extends Pivot implements Sortable
{
    use SortableTrait;

    public $incrementing = true;
}

Now if you attach() any questionnaires and attributes to each other, the order column should be filled in correctly.

from eloquent-sortable.

esl51 avatar esl51 commented on May 22, 2024

This event not firing on Pivot.

from eloquent-sortable.

freekmurze avatar freekmurze commented on May 22, 2024

I believe we can't solve this error in this package.

If you do know a good solution, feel free to PR it.

from eloquent-sortable.

Sylk avatar Sylk commented on May 22, 2024

Now if you attach() any questionnaires and attributes to each other, the order column should be filled in correctly.

Hey @bakerkretzmar I'm just getting the following error following with what you've posted.

Call to undefined method App\Http\Controllers\BookController::fromRawAttributes()

from eloquent-sortable.

pokono avatar pokono commented on May 22, 2024

On attach works fine, but it seems to loose references when calling moveOrderUp(), moveOrderUp(). etc.

SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' (SQL: update `course_module` set `order_index` = 2, `course_module`.`updated_at` = 2020-02-03 05:22:21 where `` = 56 and `` = 316)

The two where are missing foreignKey & relatedKey.

Any suggestions?

from eloquent-sortable.

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.