Php 如何将foreach保存到laravel中的变量?

Php 如何将foreach保存到laravel中的变量?,php,jquery,database,laravel,variables,Php,Jquery,Database,Laravel,Variables,我想显示以下元素: $category->getFullNameAttribute $category->id $category->email $category->image 以下是我的看法: <div class="col-md-12"> <div class="card" style="padding: 20px; overflow: auto;"> <ul id="ul-data" style="display:none;">

我想显示以下元素:

$category->getFullNameAttribute $category->id $category->email $category->image 以下是我的看法:

<div class="col-md-12">
    <div class="card" style="padding: 20px; overflow: auto;">
        <ul id="ul-data" style="display:none;">
            @foreach ($categories as $category)
                <li class="user-{{ $category->id }}">
                    {{ $category->getFullNameAttribute() }}
                    {{ $category->id }}
                    {{ $category->email }}
                    {{ $category->image }}
                    {{-- {{$category->representative}} --}}
                    @if (count($category->childes))
                        @include('management.orgchart.manageChild',['childs' => $category->childes])
                    @endif
                </li>
            @endforeach
        </ul>
        <div id="chart-container"></div>
然而,当我以这种方式显示它们时,它们都进入相同的div标题或文本中

我遇到了很大的问题,因为我需要将它分成更多的div,因为我想在底部显示电子邮件,在顶部显示名称,在图像旁边显示id以及各种其他样式选择

有人知道我如何把元素id,电子邮件,图像。。。转换成不同的变量,以便我可以轻松地操作它们

我感谢你的帮助,我会尽一切努力解决问题。 如果我没有正确地解释一些事情,请在评论中询问我,我会尽我所能更详细地解释

编辑:这是该方法的控制器:

<?php

namespace App\Http\Controllers;

use App\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;

class OrgController extends Controller
{

    /**
     * Display the OrgChart.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        Carbon::setLocale(App::getLocale());

        if (Session::get('locked') === true) {
            return redirect('/lock');
        }

        $categories = User::where('supervisor_id', '=', null)->get();
        return view('management.orgchart.index', compact('categories'));
    }
}
这是按名称的右侧标题时显示的模型窗口。 我想将数据输入该部门的名字、姓氏、电子邮件等…:

<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">Profile Window</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="text-center">
                    <div class="img-container">
                        <img src="img/default-avatar.png" class="img-circle" id="circleImage" alt="Cinque Terre" />
                    </div>
                </div>
                <div class="text-center">
                    <div id="first_name" style="display: inline-block;">First name</div> <br>
                    <div id="last_name" style="display: inline-block;">Last name</div>
                    <div id="birthday">00.10.2020</div>
                    <div id="customer_email">hello@k-tronik.de</div>
                    <div id="representative_id">Representive Person</div>
                    <br>
                </div>
                <p id="contentWin">
                    {{-- @foreach($categories as $category)
                        <li class="user-{{ $user->id }}">
                            {{ $user->getId }}
                            @if (count($user->childes))
                                @include('management.orgchart.manageChild',['childs' => $category->childes])
                            @endif
                        </li>
                    @endforeach --}}
                    Using dummy content or fake information in the Web design process can result in products with unrealistic assumptions and potentially serious design flaws. A seemingly elegant design can quickly begin to bloat with unexpected content or break under the weight of actual activity. Fake data can ensure a nice looking layout but it doesn’t reflect what a
                    Lorem Ipsum actually is usefull in the design stage as it
                    Kyle Fiedler from the Design Informer feels that distracting copy is your fault:
                    If the copy becomes distracting in the design then you are doquestions about lorem ipsum don’t.
                    Summing up, if the copy is diverting attention from the design it’s because it’s not up to task.
                    Typographers of yore didn't come up with the concept ot on it. They will be drawn to it, fiercely. Do it the wrong way and draft copy can derail your design review.
                    Asking the client to pay no attention Lorem Ipsum ing you can't win. Whenever draft copy comes up in a meeting confused questions about it ensue.
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                {{--<button type="button" class="btn btn-primary">Save changes</button>--}}
            </div>
        </div>
    </div>
</div>
这可能对你有帮助

<div class="col-md-12">
<div class="card" style="padding: 20px; overflow: auto;">
    <ul id="ul-data" style="display:none;">
        @foreach($categories as $category)
            <li class="user-{{ $category->id }}">
                <span class="getFullNameAttribute">
                    {{ $category->getFullNameAttribute()}}
                </span>
                <span class="id">
                    {{ $category->id}}
                </span>
                <span class="email">
                    {{$category->email}}
                </span>
                <span class="image">
                    {{$category->image}}
                </span>
                <span class="representative">
                    {{--{{$category->representative}}--}}
                </span>
                @if(count($category->childes))
                    @include('management.orgchart.manageChild',['childs' => $category->childes])
                @endif
            </li>
        @endforeach
    </ul>
    <div id="chart-container"></div>
</div>

上传你的控制器方法,并解释你想要显示结果的div类型你想要变量中的值是什么?它们是动态的。。只需将div添加到for循环中,并围绕相应的data@Tomm,我有一个模式窗口将弹出,我不知道如何将它引用到模式窗口中的div我不需要它在这里,我的意思是我不知道如何编辑其他div。。我在哪里能找到那个控制器?我想把上面元素中的信息显示到普通的html div中,就像这样,只是在弹出窗口中显示信息。。。div示例:Firstname@Md.JubairMizan,我对这篇文章进行了新的编辑并添加了一个控制器。我希望您有一些解决方案,所以,FWIW,在使用访问器时:您不必在模型上引用该方法。您可以简单地编写$category->full\u name,而不是$category->getFullNameAttribute
@php
    $your_variable = $category;
@endphp