Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Find the result set

Hello, I am a Chinese user, my English is not very good, I used a translation software to communicate with you, I face a problem, when I find results I'd like to add a value in the result How to set up, please? Here is my code:

$chengyuans = Jiazuchengyuan::find("jiazuid = $jiazuid");
$chengyuans -> name = 'vendor';

The data in the table is actually is not of this field.



84.4k
Accepted
answer

Jiazuchengyuan::find does return a resultset, you have to do something like:

$chengyuans = Jiazuchengyuan::find("jiazuid = $jiazuid");
foreach ($chengyuans as $chengyuan) {
    $chengyuans->name = 'vendor';
    if (!$chengyuans->save()) {
        foreach ($chengyuans->getMessages() as $message) {
            echo $message;
        }
    }
}