From 1f630eb1197dd267f4bd10225b39494eb85ad634 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Apr 2019 12:38:17 +1100 Subject: [PATCH] app/Filters/InvoiceFilters.php --- app/Http/Controllers/InvoiceController.php | 4 ++-- app/Models/Invoice.php | 6 +++++- database/factories/InvoiceFactory.php | 2 +- .../migrations/2014_10_13_000000_create_users_table.php | 2 +- database/seeds/RandomDataSeeder.php | 3 +++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index aab2be9b79..c87fa58219 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -38,9 +38,9 @@ class InvoiceController extends BaseController public function index() { - // $clients = Client::filter($filters); + $invoices = Invoice::filter($filters); - // return $this->listResponse($clients); + return $this->listResponse($invoices); } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 1950fa4195..2329900c86 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -2,13 +2,17 @@ namespace App\Models; +use App\Models\Filterable; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Invoice extends BaseModel { use MakesHash; - + use SoftDeletes; + use Filterable; + protected $guarded = [ 'id', ]; diff --git a/database/factories/InvoiceFactory.php b/database/factories/InvoiceFactory.php index 20a0559e3c..33eec50c1b 100644 --- a/database/factories/InvoiceFactory.php +++ b/database/factories/InvoiceFactory.php @@ -5,7 +5,7 @@ use Faker\Generator as Faker; $factory->define(App\Models\Invoice::class, function (Faker $faker) { return [ 'invoice_status_id' => App\Models\Invoice::STATUS_PAID, - 'invoice_number' => 'abc-123', + 'invoice_number' => $faker->text(20), 'discount' => $faker->numberBetween(1,10), 'is_amount_discount' => $faker->boolean(), 'tax_name1' => 'GST', 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 ec73559b40..104f5088f0 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -380,7 +380,7 @@ class CreateUsersTable extends Migration $t->timestamps(); $t->softDeletes(); - $t->unique(['company_id', 'client_id']); + $t->unique(['company_id', 'invoice_number']); }); Schema::create('invitations', function ($t) { diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 7bc187b14e..abf80d84de 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -91,6 +91,9 @@ class RandomDataSeeder extends Seeder /** Product Factory */ factory(\App\Models\Product::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id]); + /** Invoice Factory */ + factory(\App\Models\Invoice::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); + } }