我想将合同模型的每个属性复制到另一个模板合同模型中,依此类推。我的代码可以工作,但我对 laravel (或者实际上是 php)了解不多,我的直觉告诉我必须有更好的方法,或更优雅的方法。
fill()
Laravel 并没有变得更好。也许有一个构造函数?
相等表:
合同 -> 模板合同
章节 -> 模板章节
条款 -> 模板条款
public function storeTemplate(ContractCreateRequest $request)
{
DB::beginTransaction();
try
{
$contract = Contract::find($request->input()['type']);
$templatecontract = new TemplateContract();
$templatecontract->id = $contract->id;
$templatecontract->pid = $contract->pid;
$templatecontract->deleted = $contract->deleted;
$templatecontract->sorting = $contract->sorting;
$templatecontract->created_at = $contract->created_at;
$templatecontract->updated_at = $contract->updated_at;
$templatecontract->deleted_at = $contract->deleted_at;
$templatecontract->title = $contract->title;
$templatecontract->description = $contract->description;
$templatecontract->hidden = $contract->hidden;
$templatecontract->contract_type = $contract->contract_type;
$templatecontract->process_type = $contract->process_type;
$templatecontract->tstamp = $contract->tstamp;
$templatecontract->is_english = $contract->is_english;
$templatecontract->usecasetitle = $contract->usecasetitle;
饮歌长啸