diff --git a/app/controllers/admin/SuppliersController.php b/app/controllers/admin/SuppliersController.php index a71c9497f8..495b9aa793 100755 --- a/app/controllers/admin/SuppliersController.php +++ b/app/controllers/admin/SuppliersController.php @@ -1,6 +1,7 @@ validate($new)) { // Save the location data - $supplier->name = e(Input::get('name')); - $supplier->address = e(Input::get('address')); - $supplier->address2 = e(Input::get('address2')); - $supplier->city = e(Input::get('city')); - $supplier->state = e(Input::get('state')); - $supplier->country = e(Input::get('country')); - $supplier->zip = e(Input::get('zip')); - $supplier->contact = e(Input::get('contact')); - $supplier->phone = e(Input::get('phone')); - $supplier->fax = e(Input::get('fax')); - $supplier->email = e(Input::get('email')); - $supplier->notes = e(Input::get('notes')); - $supplier->url = $supplier->addhttp(e(Input::get('url'))); - $supplier->user_id = Sentry::getId(); + $supplier->name = e(Input::get('name')); + $supplier->address = e(Input::get('address')); + $supplier->address2 = e(Input::get('address2')); + $supplier->city = e(Input::get('city')); + $supplier->state = e(Input::get('state')); + $supplier->country = e(Input::get('country')); + $supplier->zip = e(Input::get('zip')); + $supplier->contact = e(Input::get('contact')); + $supplier->phone = e(Input::get('phone')); + $supplier->fax = e(Input::get('fax')); + $supplier->email = e(Input::get('email')); + $supplier->notes = e(Input::get('notes')); + $supplier->url = $supplier->addhttp(e(Input::get('url'))); + $supplier->user_id = Sentry::getId(); + + if (Input::file('image')) { + $image = Input::file('image'); + $file_name = str_random(25).".".$image->getClientOriginalExtension(); + $path = public_path('uploads/suppliers/'.$file_name); + Image::make($image->getRealPath())->resize(300, null, function ($constraint) { + $constraint->aspectRatio(); + $constraint->upsize(); + })->save($path); + $supplier->image = $file_name; + } // Was it created? if($supplier->save()) { @@ -134,20 +146,34 @@ class SuppliersController extends AdminController else { // Save the data - $supplier->name = e(Input::get('name')); - $supplier->address = e(Input::get('address')); - $supplier->address2 = e(Input::get('address2')); - $supplier->city = e(Input::get('city')); - $supplier->state = e(Input::get('state')); - $supplier->country = e(Input::get('country')); - $supplier->zip = e(Input::get('zip')); - $supplier->contact = e(Input::get('contact')); - $supplier->phone = e(Input::get('phone')); - $supplier->fax = e(Input::get('fax')); - $supplier->email = e(Input::get('email')); - $supplier->url = $supplier->addhttp(e(Input::get('url'))); - $supplier->notes = e(Input::get('notes')); + $supplier->name = e(Input::get('name')); + $supplier->address = e(Input::get('address')); + $supplier->address2 = e(Input::get('address2')); + $supplier->city = e(Input::get('city')); + $supplier->state = e(Input::get('state')); + $supplier->country = e(Input::get('country')); + $supplier->zip = e(Input::get('zip')); + $supplier->contact = e(Input::get('contact')); + $supplier->phone = e(Input::get('phone')); + $supplier->fax = e(Input::get('fax')); + $supplier->email = e(Input::get('email')); + $supplier->url = $supplier->addhttp(e(Input::get('url'))); + $supplier->notes = e(Input::get('notes')); + if (Input::file('image')) { + $image = Input::file('image'); + $file_name = str_random(25).".".$image->getClientOriginalExtension(); + $path = public_path('uploads/suppliers/'.$file_name); + Image::make($image->getRealPath())->resize(300, null, function ($constraint) { + $constraint->aspectRatio(); + $constraint->upsize(); + })->save($path); + $supplier->image = $file_name; + } + + if (Input::get('image_delete') == 1 && Input::file('image') == "") { + $supplier->image = NULL; + } // Was it created? if($supplier->save()) { diff --git a/app/database/migrations/2014_11_07_021042_add_image_to_supplier.php b/app/database/migrations/2014_11_07_021042_add_image_to_supplier.php new file mode 100644 index 0000000000..0efb41eb09 --- /dev/null +++ b/app/database/migrations/2014_11_07_021042_add_image_to_supplier.php @@ -0,0 +1,37 @@ +string('image')->nullable(); + + }); + + } + + /** + * Revert the changes to the table. + * + * @return void + */ + public function down() + { + Schema::table('suppliers', function(Blueprint $table) { + + $table->dropColumn('image'); + + }); + } + +} \ No newline at end of file diff --git a/app/views/backend/suppliers/edit.blade.php b/app/views/backend/suppliers/edit.blade.php index 2c1a690c80..28f5835ab8 100755 --- a/app/views/backend/suppliers/edit.blade.php +++ b/app/views/backend/suppliers/edit.blade.php @@ -30,7 +30,7 @@