【问题标题】:Passing data from controller to modal将数据从控制器传递到模态
【发布时间】:2021-09-30 15:59:15
【问题描述】:

我正在尝试从数据库表中获取数据并将其传递给模式,但它表示我传入的数组未定义。这是我的控制器:

public function displayLocNotesForModal() {
    $notesLoc = Note::all();
    
    return view('/components/callCenter/modalLocNotes', ['notesLoc' => $notesLoc]);
}

这是我的路线:

Route::get('/components/callCenter/modalLocNotes', 'App\Http\Controllers\CallCenter\NoteController@displayLocNotesForModal');

这是我的模态:

<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
    <h3 class="text-lg leading-6 font-medium text-gray-900" id="modal-headline">
        Location #{{ $title }} Notes
    </h3>
    <div class="mt-2">
        <p class="text-sm leading-5 text-gray-500">
            {{-- {{ $slot }} --}}
            @foreach($notesLoc as $notes)
                @if($notes == $title)
                    works    
                @endif
            @endforeach
        </p>
    </div>
</div>

【问题讨论】:

标签: php laravel laravel-blade


【解决方案1】:

我认为应该如下所示,假设 components 文件夹在您的 resources/views 文件夹中

return view('components.callCenter.modalLocNotes', ['notesLoc' => $notesLoc]);

还提供了指向文档Laravel nested view directories的链接

【讨论】:

    猜你喜欢
    • 2019-04-26
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多