使用雄辩的模型,您只需通过调用即可更新数据
$model->update( $data );
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这并没有更新关系.
如果您还想更新关系,则需要手动分配每个值并调用push()然后:
$model->name = $data['name'];
$model->relationship->description = $data['relationship']['description'];
$model->push();
Run Code Online (Sandbox Code Playgroud)
通过这项工作,如果您要分配大量数据,它将变得一团糟.
我喜欢这样的事情
$model->push( $data ); // this should assign the data to the model like update() does but also for the relations of $model
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
在Eloquent的文档中,据说我可以将所需关系的键传递给hasManyThrough。
假设我有名为 Country、User、Post 的模型。通过用户模型,国家模型可能有许多帖子。也就是说,我可以直接调用:
$this->hasManyThrough('Post', 'User', 'country_id', 'user_id');
Run Code Online (Sandbox Code Playgroud)
到目前为止一切正常!但是我怎样才能只为 id 为 3 的用户获取这些帖子?
有人可以帮忙吗?
我想知道如何将数据Input::all()与模型合并并保存结果.
澄清:我想做类似下面的事情:
$product = Product::find(1); // Eloquent Model
$product->merge( Input::all() ); // This is what I am looking for :)
$product->save();
Run Code Online (Sandbox Code Playgroud)