diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 985ec769f..4e7267fe3 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 Controller public 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] [] + * @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.php index a8d6208d7..0a8a0a543 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.php index adc13dc73..cdf7596d4 100644 --- a/database/seeders/ManufacturerSeeder.php +++ b/database/seeders/ManufacturerSeeder.php @@ -27,6 +27,10 @@ class ManufacturerSeeder extends Seeder Manufacturer::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.webp new file mode 100644 index 000000000..4355fcec8 Binary files /dev/null and b/public/img/demo/manufacturers/google.webp differ diff --git a/public/img/demo/manufacturers/huawei.webp b/public/img/demo/manufacturers/huawei.webp new file mode 100644 index 000000000..23a6c21df Binary files /dev/null and b/public/img/demo/manufacturers/huawei.webp differ diff --git a/public/img/demo/manufacturers/samsung.png b/public/img/demo/manufacturers/samsung.png new file mode 100644 index 000000000..0dc9444ef Binary files /dev/null and b/public/img/demo/manufacturers/samsung.png differ diff --git a/public/img/demo/manufacturers/sony.png b/public/img/demo/manufacturers/sony.png new file mode 100644 index 000000000..95753078c Binary files /dev/null and b/public/img/demo/manufacturers/sony.png differ diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 3a84d2412..b37494e7b 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.php index a73623ed3..c0b033468 100755 --- a/resources/views/manufacturers/index.blade.php +++ b/resources/views/manufacturers/index.blade.php @@ -25,37 +25,60 @@ {{-- Page content --}} @section('content') -
-
-
-
- -
-
-
-
-
+
+
+
+
+ + @if ($manufacturer_count == 0) + +
+ {{ csrf_field() }} +
+

+ {{ trans('general.seeding.manufacturers.prompt') }} + +

+
+
+ + @else + + + +
+ + + @endif +
+
+
+
@stop @section('moar_scripts') + + @include ('partials.bootstrap-table') @stop diff --git a/routes/web.php b/routes/web.php index 9d7b7af88..add1e6235 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);