Use Request instead of Input::

This commit is contained in:
snipe 2016-12-15 15:56:52 -08:00
parent c6ab34faee
commit b7a2c4c26d
2 changed files with 47 additions and 48 deletions

View file

@ -15,6 +15,7 @@ use App\Models\Asset;
use App\Models\Company; use App\Models\Company;
use Config; use Config;
use App\Helpers\Helper; use App\Helpers\Helper;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
@ -70,36 +71,36 @@ class AssetModelsController extends Controller
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return Redirect
*/ */
public function store() public function store(Request $request)
{ {
// Create a new asset model // Create a new asset model
$model = new AssetModel; $model = new AssetModel;
if (e(Input::get('depreciation_id')) == '') { if (e($request->input('depreciation_id')) == '') {
$model->depreciation_id = 0; $model->depreciation_id = 0;
} else { } else {
$model->depreciation_id = e(Input::get('depreciation_id')); $model->depreciation_id = e($request->input('depreciation_id'));
} }
if (e(Input::get('eol')) == '') { if (e($request->input('eol')) == '') {
$model->eol = 0; $model->eol = 0;
} else { } else {
$model->eol = e(Input::get('eol')); $model->eol = e($request->input('eol'));
} }
// Save the model data // Save the model data
$model->name = e(Input::get('name')); $model->name = e($request->input('name'));
$model->model_number = e(Input::get('model_number')); $model->model_number = e($request->input('model_number'));
$model->manufacturer_id = e(Input::get('manufacturer_id')); $model->manufacturer_id = e($request->input('manufacturer_id'));
$model->category_id = e(Input::get('category_id')); $model->category_id = e($request->input('category_id'));
$model->notes = e(Input::get('notes')); $model->notes = e($request->input('notes'));
$model->user_id = Auth::user()->id; $model->user_id = Auth::user()->id;
$model->requestable = Input::has('requestable'); $model->requestable = Input::has('requestable');
if (Input::get('custom_fieldset')!='') { if ($request->input('custom_fieldset')!='') {
$model->fieldset_id = e(Input::get('custom_fieldset')); $model->fieldset_id = e($request->input('custom_fieldset'));
} }
@ -132,7 +133,7 @@ class AssetModelsController extends Controller
* @since [v2.0] * @since [v2.0]
* @return String JSON * @return String JSON
*/ */
public function apiStore() public function apiStore(Request $request)
{ {
//COPYPASTA!!!! FIXME //COPYPASTA!!!! FIXME
$model = new AssetModel; $model = new AssetModel;
@ -140,18 +141,18 @@ class AssetModelsController extends Controller
$settings=Input::all(); $settings=Input::all();
$settings['eol']= null; $settings['eol']= null;
$model->name=e(Input::get('name')); $model->name=e($request->input('name'));
$model->manufacturer_id = e(Input::get('manufacturer_id')); $model->manufacturer_id = e($request->input('manufacturer_id'));
$model->category_id = e(Input::get('category_id')); $model->category_id = e($request->input('category_id'));
$model->model_number = e(Input::get('model_number')); $model->model_number = e($request->input('model_number'));
$model->user_id = Auth::user()->id; $model->user_id = Auth::user()->id;
$model->notes = e(Input::get('notes')); $model->notes = e($request->input('notes'));
$model->eol= null; $model->eol= null;
if (Input::get('fieldset_id')=='') { if ($request->input('fieldset_id')=='') {
$model->fieldset_id = null; $model->fieldset_id = null;
} else { } else {
$model->fieldset_id = e(Input::get('fieldset_id')); $model->fieldset_id = e($request->input('fieldset_id'));
} }
if ($model->save()) { if ($model->save()) {
@ -199,7 +200,7 @@ class AssetModelsController extends Controller
* @param int $modelId * @param int $modelId
* @return Redirect * @return Redirect
*/ */
public function update($modelId = null) public function update(Request $request, $modelId = null)
{ {
// Check if the model exists // Check if the model exists
if (is_null($model = AssetModel::find($modelId))) { if (is_null($model = AssetModel::find($modelId))) {
@ -208,30 +209,30 @@ class AssetModelsController extends Controller
} }
if (e(Input::get('depreciation_id')) == '') { if (e($request->input('depreciation_id')) == '') {
$model->depreciation_id = 0; $model->depreciation_id = 0;
} else { } else {
$model->depreciation_id = e(Input::get('depreciation_id')); $model->depreciation_id = e($request->input('depreciation_id'));
} }
if (e(Input::get('eol')) == '') { if (e($request->input('eol')) == '') {
$model->eol = null; $model->eol = null;
} else { } else {
$model->eol = e(Input::get('eol')); $model->eol = e($request->input('eol'));
} }
// Update the model data
$model->name = e(Input::get('name')); $model->name = e($request->input('name'));
$model->model_number = e(Input::get('model_number')); $model->model_number = e($request->input('model_number'));
$model->manufacturer_id = e(Input::get('manufacturer_id')); $model->manufacturer_id = e($request->input('manufacturer_id'));
$model->category_id = e(Input::get('category_id')); $model->category_id = e($request->input('category_id'));
$model->notes = e(Input::get('notes')); $model->notes = e($request->input('notes'));
$model->requestable = Input::has('requestable'); $model->requestable = Input::has('requestable');
if (Input::get('custom_fieldset')=='') { if ($request->input('custom_fieldset')=='') {
$model->fieldset_id = null; $model->fieldset_id = null;
} else { } else {
$model->fieldset_id = e(Input::get('custom_fieldset')); $model->fieldset_id = e($request->input('custom_fieldset'));
} }
if (Input::file('image')) { if (Input::file('image')) {
@ -245,13 +246,12 @@ class AssetModelsController extends Controller
$model->image = $file_name; $model->image = $file_name;
} }
if (Input::get('image_delete') == 1 && Input::file('image') == "") { if ($request->input('image_delete') == 1 && Input::file('image') == "") {
$model->image = null; $model->image = null;
} }
// Was it created?
if ($model->save()) { if ($model->save()) {
// Redirect to the new model page
return redirect()->route("models.index")->with('success', trans('admin/models/message.update.success')); return redirect()->route("models.index")->with('success', trans('admin/models/message.update.success'));
} else { } else {
return redirect()->back()->withInput()->withErrors($model->getErrors()); return redirect()->back()->withInput()->withErrors($model->getErrors());
@ -411,7 +411,7 @@ class AssetModelsController extends Controller
* @return String JSON * @return String JSON
*/ */
public function getDatatable($status = null) public function getDatatable(Request $request, $status = null)
{ {
$models = AssetModel::with('category', 'assets', 'depreciation', 'manufacturer'); $models = AssetModel::with('category', 'assets', 'depreciation', 'manufacturer');
@ -423,25 +423,25 @@ class AssetModelsController extends Controller
if (Input::has('search')) { if (Input::has('search')) {
$models = $models->TextSearch(Input::get('search')); $models = $models->TextSearch($request->input('search'));
} }
if (Input::has('offset')) { if (Input::has('offset')) {
$offset = e(Input::get('offset')); $offset = e($request->input('offset'));
} else { } else {
$offset = 0; $offset = 0;
} }
if (Input::has('limit')) { if (Input::has('limit')) {
$limit = e(Input::get('limit')); $limit = e($request->input('limit'));
} else { } else {
$limit = 50; $limit = 50;
} }
$allowed_columns = ['id','name','model_number']; $allowed_columns = ['id','name','model_number'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
$models = $models->orderBy($sort, $order); $models = $models->orderBy($sort, $order);
@ -492,25 +492,25 @@ class AssetModelsController extends Controller
$assets = Asset::where('model_id', '=', $modelID)->with('company', 'assetstatus'); $assets = Asset::where('model_id', '=', $modelID)->with('company', 'assetstatus');
if (Input::has('search')) { if (Input::has('search')) {
$assets = $assets->TextSearch(e(Input::get('search'))); $assets = $assets->TextSearch(e($request->input('search')));
} }
if (Input::has('offset')) { if (Input::has('offset')) {
$offset = e(Input::get('offset')); $offset = e($request->input('offset'));
} else { } else {
$offset = 0; $offset = 0;
} }
if (Input::has('limit')) { if (Input::has('limit')) {
$limit = e(Input::get('limit')); $limit = e($request->input('limit'));
} else { } else {
$limit = 50; $limit = 50;
} }
$allowed_columns = ['name', 'serial','asset_tag']; $allowed_columns = ['name', 'serial','asset_tag'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
$assets = $assets->orderBy($sort, $order); $assets = $assets->orderBy($sort, $order);

View file

@ -27,7 +27,6 @@ class AssetModel extends SnipeModel
'category_id' => 'required|integer', 'category_id' => 'required|integer',
'manufacturer_id' => 'required|integer', 'manufacturer_id' => 'required|integer',
'eol' => 'integer:min:0|max:240', 'eol' => 'integer:min:0|max:240',
'user_id' => 'integer',
); );
/** /**