<commit_before><?php
namespace App\Http\Controllers;

use App\Helpers\Helper;
use App\Models\Company;
use App\Models\Component;
use App\Models\CustomField;
use App\Models\Setting;
use App\Models\User;
use App\Models\Asset;
use Auth;
use Config;
use DB;
use Input;
use Lang;
use Mail;
use Redirect;
use Slack;
use Str;
use View;
use Validator;
use Illuminate\Http\Request;
use Gate;

/**
 * This class controls all actions related to Components for
 * the Snipe-IT Asset Management application.
 *
 * @version    v1.0
 */
class ComponentsController extends Controller
{
    /**
    * Returns a view that invokes the ajax tables which actually contains
    * the content for the components listing, which is generated in getDatatable.
    *
    * @author [<NAME>] [<<EMAIL>>]
    * @see ComponentsController::getDatatable() method that generates the JSON response
    * @since [v3.0]
     * @return \Illuminate\Contracts\View\View
    */
    public function index()
    {
        $this->authorize('view', Component::class);
        return view('components/index');
    }


    /**
    * Returns a form to create a new component.
    *
    * @author [<NAME>] [<<EMAIL>>]
    * @see ComponentsController::postCreate() method that stores the data
    * @since [v3.0]
    * @return \Illuminate\Contracts\View\View
    */
    public function create()
    {
        $this->authorize('create', Component::class);
        // Show the page
        return view('components/edit')
            ->with('item', new Component)
            ->with('category_list', Helper::categoryList('component'))
            ->with('company_list', Helper::companyList())
            ->with('location_list', Helper::locationsList());
    }


    /**
    * Validate and store data for new component.
    *
    * @author [<NAME>] [<<EMAIL>>]
    * @see ComponentsController::getCreate() method that generates the view
    * @since [v3.0]
    * @return \Illuminate\Http\RedirectResponse
     */
    public function store()
    {
        $this->authorize('create', Component::class);
        $component = new Component();
        $component->name                   = Input::get('name');
        $component->category_id            = Input::get('category_id');
        $component->location_id            = Input::get('location_id');
        $component->company_id             = Company::getIdForCurrentUser(Input::get('company_id'));
        $component->order_number           = Input::get('order_number');
        $component->min_amt                = Input::get('min_amt');
        $component->serial                 = Input::get('serial');
        $component->purchase_date       = Input::get('purchase_date');
        $component->purchase_cost       = request('purchase_cost');
        $component->qty                    = Input::get('qty');
        $component->user_id                = Auth::id();

        if ($component->save()) {
            return redirect()->route('components.index')->with('success', trans('admin/components/message.create.success'));
        }
        return redirect()->back()->withInput()->withErrors($component->getErrors());
    }

    /**
    * Return a view to edit a component.
    *
    * @author [<NAME>] [<<EMAIL>>]
    * @see ComponentsController::postEdit() method that stores the data.
    * @since [v3.0]
    * @param int $componentId
    * @return \Illuminate\Contracts\View\View
     */
    public function edit($componentId = null)
    {
        if (is_null($item = Component::find($componentId))) {
            return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist'));
        }

        $this->authorize('update', $item);

        return view('components/edit', compact('item'))
            ->with('category_list', Helper::categoryList('component'))<commit_msg>Use more modern Request handler<commit_after><?php
namespace App\Http\Controllers;

use App\Helpers\Helper;
use App\Models\Company;
use App\Models\Component;
use App\Models\CustomField;
use App\Models\Setting;
use App\Models\User;
use App\Models\Asset;
use Auth;
use Config;
use DB;
use Input;
use Lang;
use Mail;
use Redirect;
use Slack;
use Str;
use View;
use Validator;
use Illuminate\Http\Request;
use Gate;

/**
 * This class controls all actions related to Components for
 * the Snipe-IT Asset Management application.
 *
 * @version    v1.0
 */
class ComponentsController extends Controller
{
    /**
    * Returns a view that invokes the ajax tables which actually contains
    * the content for the components listing, which is generated in getDatatable.
    *
    * @author [<NAME>] [<<EMAIL>>]
    * @see ComponentsController::getDatatable() method that generates the JSON response
    * @since [v3.0]
     * @return \Illuminate\Contracts\View\View
    */
    public function index()
    {
        $this->authorize('view', Component::class);
        return view('components/index');
    }


    /**
    * Returns a form to create a new component.
    *
    * @author [<NAME>] [<<EMAIL>>]
    * @see ComponentsController::postCreate() method that stores the data
    * @since [v3.0]
    * @return \Illuminate\Contracts\View\View
    */
    public function create()
    {
        $this->authorize('create', Component::class);
        // Show the page
        return view('components/edit')
            ->with('item', new Component)
            ->with('category_list', Helper::categoryList('component'))
            ->with('company_list', Helper::companyList())
            ->with('location_list', Helper::locationsList());
    }


    /**
    * Validate and store data for new component.
    *
    * @author [<NAME>] [<<EMAIL>>]
    * @see ComponentsController::getCreate() method that generates the view
    * @since [v3.0]
    * @return \Illuminate\Http\RedirectResponse
     */
    public function store(Request $request)
    {
        $this->authorize('create', Component::class);
        $component = new Component();
        $component->name                   = $request->input('name');
        $component->category_id            = $request->input('category_id');
        $component->location_id            = $request->input('location_id');
        $component->company_id             = Company::getIdForCurrentUser($request->input('company_id'));
        $component->order_number           = $request->input('order_number', null);
        $component->min_amt                = $request->input('min_amt', null);
        $component->serial                 = $request->input('serial', null);
        $component->purchase_date          = $request->input('purchase_date', null);
        $component->purchase_cost          = $request->input('purchase_cost', null);
        $component->qty                    = $request->input('qty');
        $component->user_id                = Auth::id();

        if ($component->save()) {
            return redirect()->route('components.index')->with('success', trans('admin/components/message.create.success'));
        }
        return redirect()->back()->withInput()->withErrors($component->getErrors());
    }

    /**
    * Return a view to edit a component.
    *
    * @author [<NAME>] [<<EMAIL>>]
    * @see ComponentsController::postEdit() method that stores the data.
    * @since [v3.0]
    * @param int $componentId
    * @return \Illuminate\Contracts\View\View
     */
    public function edit($componentId = null)
    {
        if (is_null($item = Component::find($componentId))) {
            return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist'));
        }

        $this->authorize('update', $item);

        return view('components/edit', compact('item'))
            ->with('category_list', Helper::categoryList('component'))
{'fraction_non_alphanumeric': 0.14831981460023175, 'fraction_numerical': 0.0025749967812540232, 'mean_word_length': 2.704339532665713, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5821771', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2151, 'n_words': 503}