Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JacknRobots's avatar

How to use LaraCogs crudmaker "relationships" option to create many to many relation ?

Hi guys,

I've just started the development of an application on top of Laravel+Laracogs (which are both awesome)

I am currently trying to understand Laracogs crudmaker to deploy my admin panel and I'm stuck with the understanding of the "relationships" option usage.

I already deploy the app with user management and this works very fine.

Now I want to achieve something like that :

  • Users can add books
  • A book belongs to many users
  • A User can have several books (Basically, this is a many to many relation)

So at the end I should have :

  • The user table (which already exists)
  • The Book table
  • And the relational table "user_has_book"

I've tried something like this :

php artisan crudmaker:new Book \
--ui=semantic \
--migration \
--relationships="belongsToMany|App\Models\User|UserHasBook" \
--schema="id:increments,title:string"

But the result wasn't as expected. Here is what I got in my migration file :

Schema::create('books', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->integer('UserHasBook');
    $table->timestamps();
});

No relational table is created, but only a new integer field... What did I do wrong ?

Anyone can help ?

Thanks in advance :)

0 likes
4 replies
mattlantz's avatar
Level 1

You didn't do anything incorrectly. The hasOne and hasMany are covered, I had started on the belongsToMany and belongsTo but they were never finished. Looks like I missed removing that from the docs. The expected would be more like --relationships="belongsToMany|App\Models\User|user_id" it should say in the docs relation|class|column but it says name which is improper. I'll look into adding the belongsToMany and belongsTo this weekend, and updating the docs accordingly. Thanks for the post!

1 like
JacknRobots's avatar

Oh right... I understand better why I was stuck ;) Let me know about your works on the subject !

Thank you very much for your answer and your reactivity

MatthewStanford's avatar

I am Sure you know this but your docs still say relation|class|name not column. And are you still planning on supporting belongsToMany relationship? @mattlantz

Please or to participate in this conversation.