Update of a single information in Laravel

1

I'm starting to work with Laravel and wanted to know if you can help me. I need to update a single value in the database, using 'name' in the where clause instead of id.

This is for a situation of a real system that I need to migrate to Laravel soon after.

MODEL:

namespace App;
use Illuminate\Database\Eloquent\Model;
class teste extends Model
{
    protected $table = 'teste';
    protected $fillable = [
        'id',
        'nome',
        'verificado'
    ];
}

VIEW: - Send post

@foreach($nomes as $nome)
    <tr>
        <td>
            <input type="checkbox" name="nome[]" value="{{ $nome->nome }}">
        </td>
    </tr>
@endforeach

CONTROLLER:

use Illuminate\Http\Request;
use App\teste;
public function teste(Request $nome)
    {
        foreach ($nome->nome as $nome) {
            teste::table('teste')
                ->where('nome', $nome)
                ->update(['verificado' => 1]);

            Depois do update, a variável $nome é usada para tratar um arquivo xml bem aqui logo em seguida...
        }
    }

I'm sure this syntax of my update is wrong, but unfortunately I still can not understand the documentation correctly.

The update only needs to change checked from NULL to 1 and the data is unique, there is no way to have two equal names in this system.

In addition, the $ name variable is used soon after to handle a saved xml in folder (selecting the etc file). the function that handles xml works perfectly without problems, so I did not put it here. This verified is just information for the user informing that someone has already worked on it.

    
asked by anonymous 20.11.2018 / 22:02

1 answer

2

You do not need to call the table name again.

teste::where('nome', $nome)->update(['verificado' => 1]);

See more information in the documentation

    
20.11.2018 / 23:22