Pass string to uppercase - laravel

2

Good afternoon. I have the following code that perfectly saves.

public function store(Request $request)
{
    $this->validate($request, [
        'servidor' => 'required|unique:servidors|max:255',
       // 'dtprotocolo' => 'date|date_format:Y-m-d',
    ]);

    Servidor::create($request->all());

    Session::flash('create_servidor', 'Servidor cadastrado com sucesso!');

    return redirect(route('servidor.index'));
}

But I would like to change the value $ request-> server to uppercase. How to proceed?

    
asked by anonymous 08.11.2017 / 19:25

2 answers

2

At your% with% model do a Mutators that the value will always be uppercase from this setting , from this code below, as an example:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Servidor extends Model
{
    // as outras configuração do seu model continuam

    // acrescente esse método
    public function setServidorAttribute($value)
    {
        $this->attributes['servidor'] = mb_strtoupper($value);
    }
}

For more details on setting up a Mutators check the documentation Defining A Mutator .

References:

09.11.2017 / 15:34
0

If you are using inputs, you can transform the data in upper case at the time of the user's insertion. Use this javascript at the bottom of the page:

<script type="text/javascript">
// INICIO FUNÇÃO DE MASCARA MAIUSCULA
function maiuscula(z){
    v = z.value.toUpperCase();
    z.value = v;
}
//FIM DA FUNÇÃO MASCARA MAIUSCULA

In your input, use call function:

<input name="cliente" class="form-control"  placeholder="nome cliente" onkeyup="maiuscula(this)">
    
09.11.2017 / 13:46