Laravel,如何将DomDocument保存到数据库中?

Laravel, how to save DomDocument to database?

我的项目卡住了,我需要你的帮助! 我正在尝试将 domdocument 变量保存到我的数据库中。 我正在使用 Laravel 5.4

如何保存以下变量?

$title = $dom->getElementsByTagName('title');

我的控制器:

TemporaryScan::create([

'title' => ??

]);

临时扫描table:

Schema::create('temporary_scans', function (Blueprint $table) {
        $table->increments('id');
        $table->text('title');
        $table->timestamps();
    });

我不确定使用 text() 是否是正确的选择。

提前致谢。

 $ts = new TemporaryScan;
 $ts->title = $title;
 $ts->save();

在临时扫描模型中

protected $fillable = ["title"];

在控制器中

$ts->fill($request->all())->save();


<?php
$xml ='<?xml version="1.0" encoding="utf-8"?>
<books>
 <book>Patterns of Enterprise Application Architecture</book>
 <book>Design Patterns: Elements of Reusable Software Design</book>
<book>Clean Code</book>
</books>';
$dom = new DOMDocument;
$dom->loadXML($xml);
$books = $dom->getElementsByTagName('book');
$string = "";
foreach($books as $node)
 {
   $r = $dom->saveXML($node);
   $string .= $r;
 }
echo $string;
?>

并保存 $string;