diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 86afd14e7e..1188cc19ba 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -208,15 +208,23 @@ class AssetsController extends Controller } // Create the image (if one was chosen.) - if (Input::file('image')) { - $image = Input::file('image'); - $file_name = str_random(25).".".$image->getClientOriginalExtension(); + if (Input::has('image')) { + $image = Input::get('image'); + $header = explode(';', $image, 2)[0]; + $extension = substr( $header, strpos($header, '/')+1); + $image = substr( $image, strpos($image, ',')+1); + + $file_name = str_random(25).".".$extension; $path = public_path('uploads/assets/'.$file_name); - Image::make($image->getRealPath())->resize(500, null, function ($constraint) { + + //Currently resizing happens on Client. Maybe use this for thumbnails in the future? + Image::make($image) + ->resize(500, 500, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); - })->save($path); - $asset->image = $file_name; + }) + ->save($path); + $asset->image = $file_name; } @@ -233,11 +241,11 @@ class AssetsController extends Controller $log = $logaction->logaction('checkout'); } // Redirect to the asset listing page - return redirect()->to("hardware")->with('success', trans('admin/hardware/message.create.success')); + \Session::flash('success', trans('admin/hardware/message.create.success')); + return response()->json(['redirect_url' => route('hardware')]); } - return redirect()->back()->withInput()->withErrors($asset->getErrors()); - + return response()->json(['errors' => $asset->getErrors()]); } /** diff --git a/app/Http/Requests/AssetRequest.php b/app/Http/Requests/AssetRequest.php index 483bccdb89..ca3360997a 100644 --- a/app/Http/Requests/AssetRequest.php +++ b/app/Http/Requests/AssetRequest.php @@ -4,7 +4,7 @@ namespace App\Http\Requests; use App\Http\Requests\Request; use App\Models\AssetModel; - +use Session; class AssetRequest extends Request { /** @@ -53,6 +53,10 @@ class AssetRequest extends Request public function response(array $errors) { - return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag); + $this->session()->flash('errors', Session::get('errors', new \Illuminate\Support\ViewErrorBag) + ->put('default', new \Illuminate\Support\MessageBag($errors))); + + return parent::response($errors); + // return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag); } } diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 709ed4b341..618c9f30f9 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -13,9 +13,9 @@ abstract class Request extends FormRequest return $this->rules; } - public function response(array $errors) - { - $this->session->flash('errorMessages', $errors); - return $this->redirector->back()->withErrors($errors)->withInput(); - } + // public function response(array $errors) + // { + // $this->session->flash('errorMessages', $errors); + // return $this->redirector->back()->withErrors($errors)->withInput(); + // } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 3d05b0c6ca..283e915adf 100755 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -162,7 +162,6 @@ Route::group([ 'prefix' => 'api', 'middleware' => 'auth' ], function () { ); }); - }); /* diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index ea7cafb20e..6642ef88c8 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -15,7 +15,6 @@ {{ trans('general.back') }} @stop - {{-- Some room for the modals --}}