Update a single information in Laravel

Asked

Viewed 6,293 times

1

I’m starting work with Laravel and I was wondering if you could help me. I need to update a single value in the bank, using 'name' in the Where clause instead of id.

This is for a real system situation that I need to migrate to Laravel right away.

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...
        }
    }

He gives me back my mistake: Call to Undefined method Illuminate Database Query Builder::table()

I’m sure this syntax of my update is wrong, but unfortunately I still can’t understand in the documentation the correct form.

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

In addition, the $name variable is used right away to treat a folder-saved xml (selecting the file etc). the function that handles xml works perfectly smoothly, so I did not put here. This check is just information for the user informing that someone has already worked on it.

  • Your code is very wrong and you should not do so it is different to be able to do. It can happen equal names and this will already give problem your foreach you overwrite the variable of Request, so everything needs to be rethought.

  • Hello friend, this code is the beginning of a test, it will still be improved and treated as it should be done until you arrive at Prod! Thanks, hugs!

1 answer

4


  • Thanks a lot, solved. In fact, the following error appeared: "Laravel:Unknown column 'updated_at'" Searching the internet quickly, it was solved with this topic: https:/translate.googleusercontent.com/translate_c?depth=1&hl=pt-BR&prev=search&rurl=translate.google.com&sl=en&sp=nmt4&u=https://stackoverflow.com/questions/28277955/laravelunknown-column-updated-at&xid=25657,15700019,15700124,15700149,15700186,15700191,15700201&usg=ALkJrhizVyVyBDJ77sFcG0AT33SL590Ojw&#xA;&#xA;Obrigado!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.