Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Laravel5.4PHP-SQL的动态SVG图像_Php_Mysql_Laravel_Svg - Fatal编程技术网

使用Laravel5.4PHP-SQL的动态SVG图像

使用Laravel5.4PHP-SQL的动态SVG图像,php,mysql,laravel,svg,Php,Mysql,Laravel,Svg,我有26个教室,我的想法是在学校的平面图上,在SVG图像中使用颜色填充教室 已经做了,但我想我必须做26个sql查询,每个教室一个。 这是正确的还是有其他方法 控制器: public function index() { $dataClassr = Classroom::all()->where('name_classroom', 'sistemas 1')->first(); return view('welcome')->with('dataClassr

我有26个教室,我的想法是在学校的平面图上,在SVG图像中使用颜色填充教室

已经做了,但我想我必须做26个sql查询,每个教室一个。 这是正确的还是有其他方法

控制器:

public function index()
{
    $dataClassr  = Classroom::all()->where('name_classroom', 'sistemas 1')->first();

    return view('welcome')->with('dataClassr', $dataClassr);
}
视图:


递归3
//有条件的
@如果($dataClassr->availability=='不可用')
@恩迪夫
第一教室
教室2
教室3
使用foreach,可以直接打印多个元素

结果是

尝试在视图上运行foreach语句,以回显$dataClassr数组中的每个svg。

不确定,但尝试在我的注释中尝试将
first()
更改为
get()

教室::all()->where('name_教室','sistemas 1')->get();


当第一个得到第一个结果时,如果您想让它们都使用get()选项。

而不知道您的数据库设置等。因此,您的classrom名称列是
name\u class
?你能不能不简单地调用值为true的所有函数。教室::all()->where('FIELD_NAME','sistemas 1'true)->get();这应该得到所有正确的结果,然后简单地迭代它们
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 545 532.5">
    <title>Recurso 3</title>
    <g>
        <polyline points="315 484 264 483.5 264 268.5 213 268.5 213 84.5 200 84.5 200 0.5 265 0.5 265 172.5 315 172.5" style="fill: #cecece;stroke: #000;stroke-miterlimit: 10"/>
        <g>
            // Conditional
            @if($dataClassr->availability == 'not available')
              <rect x="1" y="83.5" width="221" height="177" style="fill: #fc7;stroke: #111;stroke-miterlimit: 10;stroke-width: 2px"/>
            @endif

            <rect x="265" y="4.5" width="219" height="168" style="fill: #fff;stroke: #111;stroke-miterlimit: 10;stroke-width: 2px"/>
            <rect x="315" y="172.5" width="229" height="359" style="fill: #fff;stroke: #111;stroke-miterlimit: 10;stroke-width: 2px"/>
            <text transform="translate(52.96 176.84)" style="font-size: 23.11184310913086px;font-family: MyriadPro-Regular, Myriad Pro">Class<tspan x="48.3" y="0" style="letter-spacing: -0.009993016574206285em">r</tspan><tspan x="55.63" y="0">oom 1</tspan></text>
            <text transform="translate(314.96 95.84)" style="font-size: 23.11184310913086px;font-family: MyriadPro-Regular, Myriad Pro">Class<tspan x="48.3" y="0" style="letter-spacing: -0.009993016574206285em">r</tspan><tspan x="55.63" y="0">oom 2</tspan></text>
            <text transform="translate(374.96 365.84)" style="font-size: 23.11184310913086px;font-family: MyriadPro-Regular, Myriad Pro">Class<tspan x="48.3" y="0" style="letter-spacing: -0.009993016574206285em">r</tspan><tspan x="55.63" y="0">oom 3</tspan></text>
        </g>
    </g>
</svg>