Conversation
…m intermediary pivot table
|
|
||
| class Author extends Model | ||
| { | ||
| use HasFactory; |
|
|
||
| public function books() | ||
| { | ||
| return $this->belongsToMany('App\Models\Book')->using('App\Models\AuthorBook'); |
There was a problem hiding this comment.
Use like this:
return $this->belongsToMany(Book::class)->using(AuthorBook::class);
It'll be easier for the IDE to reference.
| class AuthorBook extends Pivot | ||
| { | ||
| public $incrementing = true; | ||
| use HasFactory; |
There was a problem hiding this comment.
Trait statement should be the first line inside the Class.
| { | ||
| use HasFactory; | ||
|
|
||
| public function authors(){ |
There was a problem hiding this comment.
{ should be placed in the next line.
| public function bookOfCopies(){ | ||
| return $this->hasMany('App\Models\BookCopy'); | ||
| } | ||
|
|
There was a problem hiding this comment.
Remove unnecessary empty lines.
| { | ||
| use HasFactory; | ||
|
|
||
| public function userHaveCopy(){ |
There was a problem hiding this comment.
The naming doesn't seem right. Please check. Think about the naming from the usage. For example, in your case it would be:
$bookUser = new BookUser();
$bookUser->userHaveCopy;
$bookUser->userHaveCopy it doesn't sound good.
There was a problem hiding this comment.
Same is for the below method bookOfUser.
| { | ||
| use HasFactory; | ||
|
|
||
| public function GenreBooks(){ |
There was a problem hiding this comment.
Fix the naming and put the { on the next line.
| $table->string('name'); | ||
| $table->string('image'); | ||
| $table->string('image')->nullable(); | ||
| $table->text('description'); |
| $table->string('name'); | ||
| $table->string('logo'); | ||
| $table->string('logo')->nullable(); | ||
| $table->text('description'); |
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| class AddDropForeignOnAuthorBookTable extends Migration |
There was a problem hiding this comment.
Why creating separate migration for 'foreign keys'? It would be hard to maintain.
There was a problem hiding this comment.
could't write the drop code on down method. I have take this step.
There was a problem hiding this comment.
Done. foreign key drop added on there specific table migration file.
No description provided.