diff --git a/app/Models/Client.php b/app/Models/Client.php index f8ba506719..493148f470 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -89,6 +89,11 @@ class Client extends BaseModel return ClientSettings::buildClientSettings($this->company->settings, $this->settings); } + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } + } diff --git a/app/Models/Document.php b/app/Models/Document.php new file mode 100644 index 0000000000..97858f49f6 --- /dev/null +++ b/app/Models/Document.php @@ -0,0 +1,14 @@ +morphTo(); + } + +} diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 7f42cb648e..2dd91a301d 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -24,4 +24,9 @@ class Expense extends BaseModel { return $this->encodePrimaryKey($this->id); } + + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 7ffe5acbcb..5f92ed956a 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -53,4 +53,9 @@ class Invoice extends BaseModel { return $this->belongsTo(Client::class); } + + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 3b44618f53..dab643fe33 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -24,4 +24,9 @@ class Payment extends BaseModel { return $this->encodePrimaryKey($this->id); } + + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index c7aa15afd2..79b635e732 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -31,5 +31,10 @@ class Product extends BaseModel return $this->belongsTo(User::class); } + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } + } diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index 6933706133..18fc80291f 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -25,5 +25,9 @@ class Proposal extends BaseModel return $this->encodePrimaryKey($this->id); } + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index d58997272d..337f6fb551 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -33,4 +33,9 @@ class Quote extends BaseModel return $this->hasMany(QuoteInvitation::class); } + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } + } diff --git a/app/Models/Task.php b/app/Models/Task.php index b438eb84eb..3dde623cf3 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -25,4 +25,9 @@ class Task extends BaseModel return $this->encodePrimaryKey($this->id); } + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } + } diff --git a/app/Models/User.php b/app/Models/User.php index 31e8c21203..3465d29342 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -258,4 +258,8 @@ class User extends Authenticatable implements MustVerifyEmail } + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } } diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 01e2d3199e..b78d8b526a 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -186,8 +186,29 @@ class CreateUsersTable extends Migration }); + Schema::create('documents', function (Blueprint $table){ + $table->increments('id'); + $table->unsignedInteger('user_id'); + $table->unsignedInteger('company_id')->index(); + $table->string('path'); + $table->string('preview'); + $table->string('name'); + $table->string('type'); + $table->string('disk'); + $table->string('hash', 100); + $table->unsignedInteger('size')->nullable(); + $table->unsignedInteger('width')->nullable(); + $table->unsignedInteger('height')->nullable(); + $table->boolean('is_default')->default(0); - + $table->unsignedInteger('documentable_id'); + $table->string('documentable_type'); + $table->timestamps(); + + $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); + + }); + Schema::create('users', function (Blueprint $table) { $table->increments('id');