Skip to content

Commit

Permalink
Seed with demo images
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Oct 28, 2017
1 parent 46fb5c9 commit 4f17470
Show file tree
Hide file tree
Showing 55 changed files with 199 additions and 20 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/Api/AssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ public function destroy($id)
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.assoc_users')));
}

if ($assetmodel->image) {
try {
unlink(public_path().'/uploads/models/'.$assetmodel->image);
} catch (\Exception $e) {
\Log::error($e);
}
}

$assetmodel->delete();
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/assetmodels/message.delete.success')));

Expand Down
21 changes: 19 additions & 2 deletions app/Http/Controllers/AssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function store(ImageUploadRequest $request)
if (Input::file('image')) {

$image = Input::file('image');
$file_name = str_random(25) . "." . $image->getClientOriginalExtension();
$file_name = slug($image->getClientOriginalName()) . "." . $image->getClientOriginalExtension();
$path = public_path('uploads/models/');

if ($image->getClientOriginalExtension()!='svg') {
Expand Down Expand Up @@ -213,9 +213,17 @@ public function update(ImageUploadRequest $request, $modelId = null)
}

if (Input::file('image')) {

$image = Input::file('image');
$file_name = str_random(25) . "." . $image->getClientOriginalExtension();
$file_name = str_slug($image->getClientOriginalName()) . "." . $image->getClientOriginalExtension();
$path = public_path('uploads/models/');
$old_image = $path.$model->image;

try {
unlink($old_image);
} catch (\Exception $e) {
\Log::error($e);
}

if ($image->getClientOriginalExtension()!='svg') {
Image::make($image->getRealPath())->resize(500, null, function ($constraint) {
Expand Down Expand Up @@ -259,6 +267,15 @@ public function destroy($modelId)
// Throw an error that this model is associated with assets
return redirect()->route('models.index')->with('error', trans('admin/models/message.assoc_users'));
}

if ($model->image) {
try {
unlink(public_path().'/uploads/models/'.$model->image);
} catch (\Exception $e) {
\Log::error($e);
}
}

// Delete the model
$model->delete();

Expand Down
23 changes: 21 additions & 2 deletions app/Http/Controllers/ManufacturersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function store(ImageUploadRequest $request)

if ($request->file('image')) {
$image = $request->file('image');
$file_name = str_random(25).".".$image->getClientOriginalExtension();
$file_name = str_slug($image->getClientOriginalName()).".".$image->getClientOriginalExtension();
$path = public_path('uploads/manufacturers/'.$file_name);
Image::make($image->getRealPath())->resize(200, null, function ($constraint) {
$constraint->aspectRatio();
Expand Down Expand Up @@ -140,8 +140,17 @@ public function update(Request $request, $manufacturerId = null)

if ($request->file('image')) {
$image = $request->file('image');
$file_name = str_random(25).".".$image->getClientOriginalExtension();
$file_name = str_slug($image->getClientOriginalName()).".".$image->getClientOriginalExtension();
$path = public_path('uploads/manufacturers/'.$file_name);
$old_image = $path.$model->image;

try {
unlink($old_image);
} catch (\Exception $e) {
\Log::error($e);
}


Image::make($image->getRealPath())->resize(200, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
Expand Down Expand Up @@ -178,6 +187,16 @@ public function destroy($manufacturerId)
// Redirect to the asset management page
return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.assoc_users'));
}

if ($manufacturer->image) {
try {
unlink(public_path().'/uploads/manufacturers/'.$manufacturer->image);
} catch (\Exception $e) {
\Log::error($e);
}
}


// Delete the manufacturer
$manufacturer->delete();
// Redirect to the manufacturers management page
Expand Down
6 changes: 4 additions & 2 deletions database/factories/ActionLogFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
->update(
[
'assigned_to' => $target->id,
'assigned_type' => App\Models\User::class
'assigned_type' => App\Models\User::class,
'assigned_to' => $target->location_id,
]
);

Expand All @@ -59,7 +60,8 @@
->update(
[
'assigned_to' => $target->id,
'assigned_type' => App\Models\Location::class
'assigned_type' => App\Models\Location::class,
'assigned_to' => $target->id,
]
);

Expand Down
2 changes: 1 addition & 1 deletion database/factories/AssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$factory->define(Asset::class, function (Faker\Generator $faker) {
return [
'name' => null,
'rtd_location_id' => rand(1,30),
'rtd_location_id' => rand(1,10),
'serial' => $faker->uuid,
'status_id' => 1,
'user_id' => 1,
Expand Down
18 changes: 18 additions & 0 deletions database/factories/AssetModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'manufacturer_id' => 1,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'mbp.jpg',
];
});

Expand All @@ -43,6 +44,7 @@
'manufacturer_id' => 1,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'macbookair.jpg',
];
});

Expand All @@ -54,6 +56,7 @@
'manufacturer_id' => 2,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'surface.jpg',
];
});

Expand All @@ -65,6 +68,7 @@
'manufacturer_id' => 3,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'xps.jpg',
];
});

Expand All @@ -76,6 +80,7 @@
'manufacturer_id' => 4,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'zenbook.jpg',
];
});

Expand All @@ -87,6 +92,7 @@
'manufacturer_id' => 5,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'spectre.jpg',
];
});

Expand All @@ -98,6 +104,7 @@
'manufacturer_id' => 6,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'yoga.png',
];
});

Expand All @@ -115,6 +122,7 @@
'manufacturer_id' => 1,
'eol' => '24',
'depreciation_id' => 1,
'image' => 'imacpro.jpg',
];
});

Expand All @@ -125,6 +133,7 @@
'manufacturer_id' => 6,
'eol' => '24',
'depreciation_id' => 1,
'image' => 'lenovoi5.png',
];
});

Expand All @@ -136,6 +145,7 @@
'model_number' => '5040 (MRR81)',
'eol' => '24',
'depreciation_id' => 1,
'image' => 'optiplex.jpg',
];
});

Expand All @@ -154,6 +164,7 @@
'manufacturer_id' => 8,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'soundstation.jpg',
];
});

Expand All @@ -164,6 +175,7 @@
'manufacturer_id' => 8,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'cx3000.png',
];
});

Expand All @@ -181,6 +193,7 @@
'manufacturer_id' => 1,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'ipad.jpg',
];
});

Expand All @@ -192,6 +205,7 @@
'manufacturer_id' => 6,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'tab3.png',
];
});

Expand All @@ -209,6 +223,7 @@
'manufacturer_id' => 1,
'eol' => '12',
'depreciation_id' => 3,
'image' => 'iphone6.jpg',
];
});

Expand All @@ -219,6 +234,7 @@
'manufacturer_id' => 1,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'iphone7.jpg',
];
});

Expand All @@ -235,6 +251,7 @@
'manufacturer_id' => 7,
'eol' => '12',
'depreciation_id' => 2,
'image' => 'ultrafine.jpg',
];
});

Expand All @@ -245,6 +262,7 @@
'manufacturer_id' => 3,
'eol' => '12',
'depreciation_id' => 2,
'image' => 'ultrasharp.jpg',
];
});

Expand Down
33 changes: 22 additions & 11 deletions database/factories/ManufacturerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
return [
'name' => 'Apple',
'url' => 'https://apple.com',
'support_url' => 'https://support.apple.com'
'support_url' => 'https://support.apple.com',
'image' => 'apple.jpg',
];
});

Expand All @@ -33,7 +34,8 @@
return [
'name' => 'Microsoft',
'url' => 'https://microsoft.com',
'support_url' => 'https://support.microsoft.com'
'support_url' => 'https://support.microsoft.com',
'image' => 'microsoft.png',
];
});

Expand All @@ -42,7 +44,8 @@
return [
'name' => 'Dell',
'url' => 'https://dell.com',
'support_url' => 'https://support.dell.com'
'support_url' => 'https://support.dell.com',
'image' => 'dell.png',
];
});

Expand All @@ -51,7 +54,8 @@
return [
'name' => 'Asus',
'url' => 'https://asus.com',
'support_url' => 'https://support.asus.com'
'support_url' => 'https://support.asus.com',
'image' => 'asus.png',
];
});

Expand All @@ -60,7 +64,8 @@
return [
'name' => 'HP',
'url' => 'https://hp.com',
'support_url' => 'https://support.hp.com'
'support_url' => 'https://support.hp.com',
'image' => 'hp.png',
];
});

Expand All @@ -69,7 +74,8 @@
return [
'name' => 'Lenovo',
'url' => 'https://lenovo.com',
'support_url' => 'https://support.lenovo.com'
'support_url' => 'https://support.lenovo.com',
'image' => 'lenovo.jpg',
];
});

Expand All @@ -78,7 +84,8 @@
return [
'name' => 'LG',
'url' => 'https://lg.com',
'support_url' => 'https://support.lg.com'
'support_url' => 'https://support.lg.com',
'image' => 'lg.jpg',
];
});

Expand All @@ -87,7 +94,8 @@
return [
'name' => 'Polycom',
'url' => 'https://polycom.com',
'support_url' => 'https://support.polycom.com'
'support_url' => 'https://support.polycom.com',
'image' => 'polycom.png',
];
});

Expand All @@ -96,7 +104,8 @@
return [
'name' => 'Adobe',
'url' => 'https://adobe.com',
'support_url' => 'https://support.adobe.com'
'support_url' => 'https://support.adobe.com',
'image' => 'adobe.jpg',
];
});

Expand All @@ -106,7 +115,8 @@
return [
'name' => 'Avery',
'url' => 'https://avery.com',
'support_url' => 'https://support.avery.com'
'support_url' => 'https://support.avery.com',
'image' => 'avery.png',
];
});

Expand All @@ -115,7 +125,8 @@
return [
'name' => 'Crucial',
'url' => 'https://crucial.com',
'support_url' => 'https://support.crucial.com'
'support_url' => 'https://support.crucial.com',
'image' => 'crucial.jpg',
];
});

Expand Down
3 changes: 2 additions & 1 deletion database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
'state' => $faker->stateAbbr,
'country' => $faker->countryCode,
'currency' => $faker->currencyCode,
'zip' => $faker->postcode
'zip' => $faker->postcode,
'image' => rand(1,9).'.jpg',
];
});

Expand Down
Loading

0 comments on commit 4f17470

Please sign in to comment.