简体   繁体   English

无法在Laravel中的刀片文件中显示表数据

[英]unable to display table data in blade file in Laravel

Need display table data in laravel on show.blade.php file it is generated from TaskController.php 需要在laravel的show.blade.php文件上显示表数据,它是从TaskController.php生成的

public function index()
{
    $tasks = Task::all();
return view('tasks.index')->with('tasks', $tasks);

}

this is index.blade.php 这是index.blade.php

@if(isset($tasks))

@foreach ($tasks as $task)

<h1>{{ $task->task_name }}</h1>

@endforeach

@endif

include this index with file to show.blade.php 将此索引与文件一起显示到show.blade.php

@include('tasks.index')

but not generate any results???? 但没有产生任何结果???? No any error??? 没有任何错误??? how to fix this 如何解决这个问题

You need to check that, is it an array or object. 您需要检查它是数组还是对象。 Try like below, it will work 尝试如下,它将起作用

@if (is_array($tasks) || is_object($tasks))
@foreach ($tasks as $task)

<h1>{{ $task->task_name }}</h1>

@endforeach

@endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM