Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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
Php 试图将变量传递给视图,但视图-laravel中没有显示任何内容_Php_Laravel - Fatal编程技术网

Php 试图将变量传递给视图,但视图-laravel中没有显示任何内容

Php 试图将变量传递给视图,但视图-laravel中没有显示任何内容,php,laravel,Php,Laravel,试图将变量传递给视图,但视图中未显示任何内容 控制器代码: public function postCreatePost(Request $request, $wordID) { $postsInWord = Post::where('words_id', $wordID)->get(); return redirect()->back()->with('postsInWord', $postsInWord); @if (isset($postsInWord)

试图将变量传递给视图,但视图中未显示任何内容

控制器代码:

public function postCreatePost(Request $request, $wordID)
{
    $postsInWord = Post::where('words_id', $wordID)->get();
    return redirect()->back()->with('postsInWord', $postsInWord);
@if (isset($postsInWord))
    @foreach ($postsInWord as $postsInWord)
    <p>{{$postsInWord->body}}</p>
    @endforeach
@endif
查看代码:

public function postCreatePost(Request $request, $wordID)
{
    $postsInWord = Post::where('words_id', $wordID)->get();
    return redirect()->back()->with('postsInWord', $postsInWord);
@if (isset($postsInWord))
    @foreach ($postsInWord as $postsInWord)
    <p>{{$postsInWord->body}}</p>
    @endforeach
@endif
@if(isset($postsInWord))
@foreach($postsInWord作为$postsInWord)
{{$postsInWord->body}

@endforeach @恩迪夫
无法使用重定向发送变量

尽管您可以使用如下数据传递会话

return redirect()->back()->with('data', 'some kind of data');
然后,您可以使用以下方法从刀片模板获取数据:

@if (session('data'))
    <div class="alert alert-success">
        {{ session('data') }}
    </div>
@endif
@if(会话('data'))
{{session('data')}
@恩迪夫

更多信息:

您不能使用重定向发送变量

尽管您可以使用如下数据传递会话

return redirect()->back()->with('data', 'some kind of data');
然后,您可以使用以下方法从刀片模板获取数据:

@if (session('data'))
    <div class="alert alert-success">
        {{ session('data') }}
    </div>
@endif
@if(会话('data'))
{{session('data')}
@恩迪夫

更多信息:

您需要更改
return
语句

return redirect()->back()->with('data', ['postsInWord']);

试试这个..

您需要更改
return
语句

return redirect()->back()->with('data', ['postsInWord']);

试试这个..

尝试了会话代码,仍然为空。。不确定为什么键入会话代码,仍然为空。。不确定为什么YPLZ会尝试在控制器和刀片中简单地打印阵列。调试会更好。plz检查是否出现任何错误或只是显示空白页?plz尝试简单地在控制器和刀片中打印阵列。这将更好地进行调试。plz检查是否出现任何错误或仅显示空白页?