IM解析XML試圖生成一個XML,但即時得到一個錯誤:FatalErrorException in 6955f07d83b93bb8aa89577b116866e228e0c155.php line 1 syntax error, unexpected 'version' (T_STRING).
在laravel
我無法弄清楚什麼即時做錯了我的代碼。
我的控制器功能是:
public function feed($gallery_id){
$products = Products::select("id","title","brand","url","path")->where("gallery_id",$gallery_id)->get();
foreach ($products as $product) {
$product->path = url($product->path);
}
return response()->view('xml.gallery', compact('products'))->header('Content-Type', 'text/xml');
}
我的刀片(xml.gallery):
<?xml version="1.0"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>Test Store</title>
<link>http://domain.com</link>
<description>An example item from the feed</description>
@foreach($products as $product)
<item>
<g:id>1</g:id>
<g:title>something</g:title>
<g:description>Solid plastic Dog Bowl in marine blue color</g:description>
<g:link>http://www.zara.com</g:link>
<g:image
_link>http://domain.com/images/photos_gallery/14788772681.png</g:image_link>
<g:price>12 GBP</g:price>
<g:brand>Nike</g:brand>
<g:availability>in stock</g:availability>
<g:condition>new</g:condition>
</item>
@endforeach
</channel>
</rss>