PHP code example of sorokin-fm / laravel-request-sanitizer

1. Go to this page and download the library: Download sorokin-fm/laravel-request-sanitizer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sorokin-fm / laravel-request-sanitizer example snippets


    public function update(UpdateRequest $request, $id)
    {
        /** @var SomeModel $model */
        $model = SomeModel::find($id);
        $model->fill($request->input());
        $model->save();

        return back()
            ->with('success', __('Some model has been changed'));
    }

$values = $request->input();
$values['checkbox1'] = $values['checkbox1'] ? 1 : 0;
$values['checkbox2'] = $values['checkbox2'] ? 1 : 0;
$model->fill($values);

$values = $request->input();

$file = $request->file('picture');
if ($file) {
    $filename = Transliteration::make(
        pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME),
        ['type' => 'filename', 'lowercase' => true]);

    $filename .= '.' . $file->getClientOriginalExtension();

    $file->move($filePath, $filename);

    $values['picture'] = $filename;
}

$file = $request->file('thumb');
if ($file) {
    $filename = Transliteration::make(
        pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME),
        ['type' => 'filename', 'lowercase' => true]);

    $filename .= '.' . $file->getClientOriginalExtension();

    $file->move($filePath, $filename);

    $values['thumb'] = $filename;
}

$model->fill($values);

    public function update(UpdateRequest $request, $id)
    {
        /** @var SomeModel $model */
        $model = SomeModel::find($id);
        $model->fill($request->sanitize());
        $model->save();

        return back()
            ->with('success', __('Some model has been changed'));
    }