some progress
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Author extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'bio',
|
||||
];
|
||||
|
||||
/**
|
||||
* The books that belong to the author.
|
||||
*/
|
||||
public function books()
|
||||
{
|
||||
return $this->belongsToMany(Book::class, 'author_book')->withTimestamps();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,14 @@ class Book extends Model
|
||||
'category_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Use slug for route model binding and URL generation.
|
||||
*/
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'slug';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category that owns the book.
|
||||
*/
|
||||
@@ -31,4 +39,36 @@ class Book extends Model
|
||||
{
|
||||
return $this->hasOne(Summary::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The authors that belong to the book.
|
||||
*/
|
||||
public function authors()
|
||||
{
|
||||
return $this->belongsToMany(Author::class, 'author_book')->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Users who saved this book to their readlist.
|
||||
*/
|
||||
public function savedByUsers()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'readlist_items')->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports submitted for this book's summary.
|
||||
*/
|
||||
public function reports()
|
||||
{
|
||||
return $this->hasMany(SummaryReport::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reviews left by users for this book's summary.
|
||||
*/
|
||||
public function reviews()
|
||||
{
|
||||
return $this->hasMany(SummaryReview::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SummaryReport extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'book_id',
|
||||
'summary_id',
|
||||
'reason',
|
||||
'details',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function book()
|
||||
{
|
||||
return $this->belongsTo(Book::class);
|
||||
}
|
||||
|
||||
public function summary()
|
||||
{
|
||||
return $this->belongsTo(Summary::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SummaryRequest extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'gutenberg_id',
|
||||
'title',
|
||||
'notes',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SummaryReview extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'book_id',
|
||||
'summary_id',
|
||||
'rating',
|
||||
'comment',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function book()
|
||||
{
|
||||
return $this->belongsTo(Book::class);
|
||||
}
|
||||
|
||||
public function summary()
|
||||
{
|
||||
return $this->belongsTo(Summary::class);
|
||||
}
|
||||
}
|
||||
@@ -45,4 +45,20 @@ class User extends Authenticatable
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Books saved by the user in their readlist.
|
||||
*/
|
||||
public function readlistBooks()
|
||||
{
|
||||
return $this->belongsToMany(Book::class, 'readlist_items')->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reviews authored by the user.
|
||||
*/
|
||||
public function reviews()
|
||||
{
|
||||
return $this->hasMany(SummaryReview::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user