From f958effb81155ac08b0828f938aaa70fd81a5b0f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 28 Apr 2019 15:31:32 +1000 Subject: [PATCH] Documents --- app/Models/Client.php | 5 ++++ app/Models/Document.php | 14 +++++++++++ app/Models/Expense.php | 5 ++++ app/Models/Invoice.php | 5 ++++ app/Models/Payment.php | 5 ++++ app/Models/Product.php | 5 ++++ app/Models/Proposal.php | 4 ++++ app/Models/Quote.php | 5 ++++ app/Models/Task.php | 5 ++++ app/Models/User.php | 4 ++++ .../2014_10_13_000000_create_users_table.php | 23 ++++++++++++++++++- 11 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 app/Models/Document.php diff --git a/app/Models/Client.php b/app/Models/Client.php index f8ba50671913..493148f470bd 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 000000000000..97858f49f69d --- /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 7f42cb648e59..2dd91a301d8c 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 7ffe5acbcbcc..5f92ed956a2a 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 3b44618f53c8..dab643fe3357 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 c7aa15afd2b1..79b635e7321d 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 693370613334..18fc80291f16 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 d58997272dca..337f6fb5519c 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 b438eb84eb1d..3dde623cf3f0 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 31e8c2120358..3465d293425c 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 01e2d3199e74..b78d8b526a31 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');