Added ability to seed manufacturers
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
2a2d118973
commit
e5dc13e48c
10 changed files with 134 additions and 29 deletions
|
@ -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] [<snipe@snipe.net>]
|
||||
* @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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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',
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'.'/';
|
||||
|
|
BIN
public/img/demo/manufacturers/google.webp
Normal file
BIN
public/img/demo/manufacturers/google.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
public/img/demo/manufacturers/huawei.webp
Normal file
BIN
public/img/demo/manufacturers/huawei.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
public/img/demo/manufacturers/samsung.png
Normal file
BIN
public/img/demo/manufacturers/samsung.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
BIN
public/img/demo/manufacturers/sony.png
Normal file
BIN
public/img/demo/manufacturers/sony.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -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',
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
@ -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')
|
||||
@stop
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue