是否可以将像 @if 这样的刀片指令传递到 laravel 的字符串中

少年波德尔

这是我在控制器中尝试过的代码

$categories = Category::where('categories.name', 'LIKE', '%' . $category_name . '%')
                ->where('categories.category_code', 'LIKE', '%' . $category_code . '%')->get();
            $category_data = $categories->count();
            if ($category_data > 0) {
                $i = 1;
                foreach ($categories as $category) {
                    $output .=
                        '<tr>
                <td>' . $i++ . '</td>
                <td><img src="' . asset($category->photo) . '" class="img-fluid" style="width: 170px; object-fit: cover;"></td>
                <td>' . $category->name . '</td>
                <td>' . $category->category_code . '</td>
                <td><a href="' . route("category.edit", $category->id) . '" class="btn btn-warning">
                                        <i class="icofont-ui-settings icofont-1x"></i>
                                    </a>
                                    @if($delete == "yes")
                                    <form action="' . route("category.destroy", $category->id) . '" method="POST" class="d-inline-block" onsubmit="return confirm("Are you sure to delete the item?")">
                                        @csrf
                                        @method("DELETE")
                                        <button class="btn btn-outline-danger" type="submit"><i class="icofont-close icofont-1x"></i></button>
                                    </form>
                                    @endif
                                </td>
                                </tr>';
                }
                return Response($output);

刀片文件中的代码,jquery

$('#filtersearch').click(function() {
        var category_name = $('#category_name').val();
        var category_code = $('#category_code').val();
        // alert(category_name)
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        })

        $.get('/categorysearch', {
                category_name: category_name,
                category_code: category_code
            },
            function(data) {
                $('#filter_data').html(data);
            })
    })

输出看起来像这样所有刀片指令都显示为字符串

有没有办法开发这个,任何解决方案都会非常棒。谢谢!

阿卡什·巴拉尼

您必须在 laravel 中使用 Concatenation 来解析字符串:


    foreach ($categories as $category) {
                $output .=
                    '<tr>
    <td>' . $i++ . '</td>
    <td><img src="' . asset($category->photo) . '" class="img-fluid" style="width: 170px; object-fit: cover;"></td>
    <td>' . $category->name . '</td>
    <td>' . $category->category_code . '</td>
    <td><a href="' . route("category.edit", $category->id) . '" class="btn btn-warning">
        <i class="icofont-ui-settings icofont-1x"></i>
        </a>';
        if($delete == "yes"){
            $output .= '<form action="' . route("category.destroy", $category->id) . '" method="POST" class="d-inline-block" onsubmit="return confirm("Are you sure to delete the item?")">';
            $output .= '<input type="hidden" name="_token" value="'.csrf_token().'">';
            $output .= '<input type="hidden" name="_method" value="DELETE"><button class="btn btn-outline-danger" type="submit"><i class="icofont-close icofont-1x"></i></button>
        </form>';
        }
                $output .='</td></tr>';
            }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将语言环境字符串传递给 laravel 中的 Lang::get 方法

如何将查询字符串参数传递给Laravel4中的路由

将时间字符串存储到Laravel中的TIME列

从laravel刀片上的字符串中删除HTML标签

在Laravel刀片模板中截断字符串

在laravel刀片模板中爆炸字符串

在javascript字符串中连接laravel刀片变量

如何将数据从ToolServiceProvider传递到Laravel Nova中的导航刀片?

如何将电子邮件变量从类传递到laravel中的刀片服务器

在powershell中,是否可以将这样的字符串“name:eric,city:tokyo”转换为json?

Django将变量传递到字符串中

将字符串传递到VBA中的范围函数

将字符串值与 PHP/Laravel 中的字符串数组进行比较?

我可以从Laravel的Observer中将变量传递到刀片吗?

Laravel Ajax数据中的数组到字符串

laravel中数组到字符串的转换

在laravel中数组到字符串的转换

Laravel中数组到字符串的转换错误

如何在像“这是我的字符串”这样包裹的字符串中创建 '

将查询字符串保留在Laravel中

Laravel Mail没有将变量传递到刀片模板

Vue / Laravel-将数据从刀片传递到Vue组件

Laravel 4 将输入从刀片传递到控制器

将数据从控制器传递到刀片视图laravel

是否可以像字符串一样将json包装在json字段中?

如何在 Scala 中创建像 "?, ?, ?, ?, ?, ?, ?" 这样的字符串?

在字符串中回显出像cat这样的变量

将mathod保存在数据库中导致laravel中的数组到字符串转换错误

将字符串而不是变量传递给刀片文件中的子 Livewire 组件