Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model branch #37

Open
wants to merge 47 commits into
base: database_migration_seed
Choose a base branch
from
Open

Model branch #37

wants to merge 47 commits into from

Conversation

alamriku
Copy link
Owner

@alamriku alamriku commented Nov 7, 2020

No description provided.


class Author extends Model
{
use HasFactory;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add SoftDeletes trait.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in other places too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public function books()
{
return $this->belongsToMany('App\Models\Book')->using('App\Models\AuthorBook');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use like this:

return $this->belongsToMany(Book::class)->using(AuthorBook::class);

It'll be easier for the IDE to reference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in other places too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

class AuthorBook extends Pivot
{
public $incrementing = true;
use HasFactory;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trait statement should be the first line inside the Class.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
use HasFactory;

public function authors(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ should be placed in the next line.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public function bookOfCopies(){
return $this->hasMany('App\Models\BookCopy');
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary empty lines.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
use HasFactory;

public function userHaveCopy(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same is for the below method bookOfUser.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
use HasFactory;

public function GenreBooks(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the naming and put the { on the next line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in other places too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -16,7 +16,7 @@ public function up()
Schema::create('authors', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('image');
$table->string('image')->nullable();
$table->text('description');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be nullable.

@@ -16,7 +16,7 @@ public function up()
Schema::create('publications', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('logo');
$table->string('logo')->nullable();
$table->text('description');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be nullable.

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddDropForeignOnAuthorBookTable extends Migration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why creating separate migration for 'foreign keys'? It would be hard to maintain.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could't write the drop code on down method. I have take this step.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. foreign key drop added on there specific table migration file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants