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!
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 :)
Please or to participate in this conversation.