小编Jar*_*rry的帖子

Eloquent - 更新集合中的所有模型

我想在集合的所有模型中设置某个属性.

在纯SQL中:

UPDATE table SET att = 'foo' WHERE id in (1,2,3)
Run Code Online (Sandbox Code Playgroud)

我有的代码:

$models = MyModel::findMany([1,2,3]);
$models->update(['att'=>'foo']);
Run Code Online (Sandbox Code Playgroud)

取自这里

但不起作用.我越来越

Call to undefined method Illuminate\Database\Eloquent\Collection::update()
Run Code Online (Sandbox Code Playgroud)

我发现它使用查询构建器构建查询的唯一方法,但我宁愿避免这种情况.

php laravel eloquent

10
推荐指数
2
解决办法
2万
查看次数

在php中序列化匿名函数

有没有办法在PHP中序列化匿名函数?

我发现这个http://www.htmlist.com/development/extending-php-5-3-closures-with-serialization-and-reflection/

protected function _fetchCode()
{
    // Open file and seek to the first line of the closure
    $file = new SplFileObject($this->reflection->getFileName());
    $file->seek($this->reflection->getStartLine()-1);

    // Retrieve all of the lines that contain code for the closure
    $code = '';
    while ($file->key() < $this->reflection->getEndLine())
    {
        $code .= $file->current();
        $file->next();
    }

    // Only keep the code defining that closure
    $begin = strpos($code, 'function');
    $end = strrpos($code, '}');
    $code = substr($code, $begin, $end - $begin + 1);

    return $code;
}
Run Code Online (Sandbox Code Playgroud)

但这取决于关闭的内部实现.

有没有未来计划实施封闭序列化?

php serialization anonymous-function

7
推荐指数
1
解决办法
6214
查看次数