A free open source IT asset/license management system
Added ability to seed manufacturers
snipee5dc13e48cc9
diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.phpindex 985ec769fc..4e7267fe3c 100755--- a/app/Http/Controllers/ManufacturersController.php+++ b/app/Http/Controllers/ManufacturersController.php@@ -6,6 +6,7 @@ use App\Http\Requests\ImageUploadRequest;use App\Models\Actionlog;use App\Models\Manufacturer;use Illuminate\Http\Request;+use Illuminate\Support\Facades\Artisan;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\Storage;use Illuminate\Support\Facades\Log;@@ -31,7 +32,28 @@ class ManufacturersController extends Controllerpublic function index() : View{$this->authorize('index', Manufacturer::class);- return view('manufacturers/index');+ $manufacturer_count = Manufacturer::withTrashed()->count();+ return view('manufacturers/index')->with('manufacturer_count', $manufacturer_count);+ }++ /**+ * Returns a view that invokes the ajax tables which actually contains+ * the content for the manufacturers listing, which is generated in getDatatable.+ *+ * @author [A. Gianotto] [<[email protected]>]+ * @see Api\ManufacturersController::index() method that generates the JSON response+ * @since [v1.0]+ */+ public function seed() : RedirectResponse+ {+ $this->authorize('index', Manufacturer::class);++ if (Manufacturer::withTrashed()->count() == 0) {+ Artisan::call('db:seed', ['--class' => 'ManufacturerSeeder']);+ return redirect()->route('manufacturers.index')->with('success', trans('general.seeding.manufacturers.success'));+ }++ return redirect()->route('manufacturers.index')->with('error', 'could not seed - manufacturers already exist');}/**diff --git a/database/factories/ManufacturerFactory.php b/database/factories/ManufacturerFactory.phpindex a8d6208d7e..0a8a0a543e 100644--- a/database/factories/ManufacturerFactory.php+++ b/database/factories/ManufacturerFactory.php@@ -166,4 +166,49 @@ class ManufacturerFactory extends Factory];});}++ public function samsung()+ {+ return $this->state(function () {+ return [+ 'name' => 'Samsung',+ 'url' => 'https://www.samsung.com',+ 'support_url' => 'https://www.samsung.com/support/',+ 'image' => 'samsung.png',+ ];+ });+ }++ public function google()+ {+ return $this->state(function () {+ return [+ 'name' => 'Google',+ 'url' => 'https://www.google.com',+ 'image' => 'google.webp',+ ];+ });+ }++ public function huawei()+ {+ return $this->state(function () {+ return [+ 'name' => 'Huawei',+ 'url' => 'https://consumer.huawei.com/',+ 'image' => 'huawei.webp',+ ];+ });+ }++ public function sony()+ {+ return $this->state(function () {+ return [+ 'name' => 'Sony',+ 'url' => 'https://electronics.sony.com',+ 'image' => 'sony.png',+ ];+ });+ }}diff --git a/database/seeders/ManufacturerSeeder.php b/database/seeders/ManufacturerSeeder.phpindex adc13dc73e..cdf7596d45 100644--- a/database/seeders/ManufacturerSeeder.php+++ b/database/seeders/ManufacturerSeeder.php@@ -27,6 +27,10 @@ class ManufacturerSeeder extends SeederManufacturer::factory()->count(1)->adobe()->create(['created_by' => $admin->id]);Manufacturer::factory()->count(1)->avery()->create(['created_by' => $admin->id]);Manufacturer::factory()->count(1)->crucial()->create(['created_by' => $admin->id]);+ Manufacturer::factory()->count(1)->samsung()->create(['created_by' => $admin->id]);+ Manufacturer::factory()->count(1)->google()->create(['created_by' => $admin->id]);+ Manufacturer::factory()->count(1)->huawei()->create(['created_by' => $admin->id]);+ Manufacturer::factory()->count(1)->sony()->create(['created_by' => $admin->id]);$src = public_path('/img/demo/manufacturers/');$dst = 'manufacturers'.'/';diff --git a/public/img/demo/manufacturers/google.webp b/public/img/demo/manufacturers/google.webpnew file mode 100644index 0000000000..4355fcec82Binary files /dev/null and b/public/img/demo/manufacturers/google.webp differdiff --git a/public/img/demo/manufacturers/huawei.webp b/public/img/demo/manufacturers/huawei.webpnew file mode 100644index 0000000000..23a6c21dfeBinary files /dev/null and b/public/img/demo/manufacturers/huawei.webp differdiff --git a/public/img/demo/manufacturers/samsung.png b/public/img/demo/manufacturers/samsung.pngnew file mode 100644index 0000000000..0dc9444ef0Binary files /dev/null and b/public/img/demo/manufacturers/samsung.png differdiff --git a/public/img/demo/manufacturers/sony.png b/public/img/demo/manufacturers/sony.pngnew file mode 100644index 0000000000..95753078c9Binary files /dev/null and b/public/img/demo/manufacturers/sony.png differdiff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.phpindex 3a84d2412f..b37494e7b5 100644--- a/resources/lang/en-US/general.php+++ b/resources/lang/en-US/general.php@@ -615,4 +615,12 @@ return ['cost_each' => ':amount each','remove_current_image' => 'Remove current :type image',+ 'seeding' => [+ 'manufacturers' => [+ 'button' => 'Create Manufacturers',+ 'prompt' => 'You do not have any manufacturers yet. Would you like to seed a list of common manufacturers? (THIS WILL OVERWRITE EXISTING MANUFACTURERS, including those that have been soft-deleted.)',+ 'success' => 'Manufacturers seeded successfully',+ ],+ ],+];diff --git a/resources/views/manufacturers/index.blade.php b/resources/views/manufacturers/index.blade.phpindex a73623ed3a..c0b033468c 100755--- a/resources/views/manufacturers/index.blade.php+++ b/resources/views/manufacturers/index.blade.php@@ -25,37 +25,60 @@{{-- Page content --}}@section('content')-<div class="row">- <div class="col-md-12">- <div class="box box-default">- <div class="box-body">- <table- data-columns="{{ \App\Presenters\ManufacturerPresenter::dataTableLayout() }}"- data-cookie-id-table="manufacturersTable"- data-pagination="true"- data-id-table="manufacturersTable"- data-search="true"- data-side-pagination="server"- data-show-columns="true"- data-show-fullscreen="true"- data-show-export="true"- data-show-refresh="true"- data-sort-order="asc"- id="manufacturersTable"- class="table table-striped snipe-table"- data-url="{{route('api.manufacturers.index', ['deleted' => (request('deleted')=='true') ? 'true' : 'false' ]) }}"- data-export-options='{- "fileName": "export-manufacturers-{{ date('Y-m-d') }}",- "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]- }'>- </table>- </div><!-- /.box-body -->- </div><!-- /.box -->- </div>-</div>+ <div class="row">+ <div class="col-md-12">++ <div class="box box-default">+ <div class="box-body">++ @if ($manufacturer_count == 0)++ <form action="{{ route('manufacturers.seed') }}" method="POST">+ {{ csrf_field() }}+ <div class="callout callout-info">+ <p>+ {{ trans('general.seeding.manufacturers.prompt') }}+ <button class="btn btn-sm btn-primary hidden-print" rel="noopener">+ {{ trans('general.seeding.manufacturers.button') }}+ </button>+ </p>+ </div>+ </form>++ @else++ <table+ data-columns="{{ \App\Presenters\ManufacturerPresenter::dataTableLayout() }}"+ data-cookie-id-table="manufacturersTable"+ data-pagination="true"+ data-id-table="manufacturersTable"+ data-search="true"+ data-side-pagination="server"+ data-show-columns="true"+ data-show-fullscreen="true"+ data-show-export="true"+ data-show-refresh="true"+ data-sort-order="asc"+ id="manufacturersTable"+ class="table table-striped snipe-table"+ data-url="{{route('api.manufacturers.index', ['deleted' => (request('deleted')=='true') ? 'true' : 'false' ]) }}"+ data-export-options='{+ "fileName": "export-manufacturers-{{ date('Y-m-d') }}",+ "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]+ }'>+ </table>+++ @endif+ </div><!-- /.box-body -->+ </div><!-- /.box -->+ </div>+ </div>@stop@section('moar_scripts')++@include ('partials.bootstrap-table')@stopdiff --git a/routes/web.php b/routes/web.phpindex 9d7b7af888..add1e62354 100644--- a/routes/web.php+++ b/routes/web.php@@ -59,6 +59,9 @@ Route::group(['middleware' => 'auth'], function () {Route::group(['prefix' => 'manufacturers', 'middleware' => ['auth']], function () {Route::post('{manufacturers_id}/restore', [ManufacturersController::class, 'restore'] )->name('restore/manufacturer');+ Route::post('seed', [ManufacturersController::class, 'seed'] )->name('manufacturers.seed');++});Route::resource('manufacturers', ManufacturersController::class);