【问题标题】:Fecthing the data from database in Laravel 5.1在 Laravel 5.1 中从数据库中获取数据
【发布时间】:2015-11-26 08:45:03
【问题描述】:

美好的一天 我在尝试从数据库中获取数据时遇到了一些错误

这是我的代码

我的表名是会议,我使用正式文档编写代码

controllers.php

public function meetingdet()
{
    $mretive = \DB::table('meeting')-> $name = $request->input('meetingname');}

查看

    <table border="1"  >
<tr>
<td><b>blah</b> </td>
<td><b>blah</b> </td></tr>
<tr>    
<td>
</td>
<td><li>foreach ($name as $retrive) {
    echo $retrive-> meeting;}
          @endforeach
</li>
</td>
</tr>
     </table>

但这就是我所看到的

语法错误,意外的 'endforeach' (T_ENDFOREACH) 和我删除 endforeach 它为我显示 for each 而不获取数据

顺便说一句,我正在开发 laravel 5.1

问候

【问题讨论】:

  • 您的查询有误。你能指出你的型号吗?

标签: php html mysql laravel-5.1


【解决方案1】:

您可以尝试以下示例代码:

controllers.php

//include your model file
use App\model;

public function meetingdet()
{
$meetingData = model::getMeetingData();
$view = array(
              'name'=>$meetingData
            );
return view('test', compact('meetingData'));
}

模型.php

public static function getMeetingData()
{
    $value=DB::table('meeting')->orderBy('meeting_id', 'asc')->get();
    return $value;
}

view.blade.php

<table border="1"  >
<tr>
<td><b>blah</b> </td>
<td><b>blah</b> </td></tr>
<tr>    
<td>
</td>
<td>
<ul>
<li>
@foreach ($meetingData as $retrive)
{{{ $retrive->meeting_id }}}
@endforeach
</li>
</ul>
</td>
</tr>
</table>

【讨论】:

  • 谢谢,但它仍然向我显示错误未定义变量:名称
  • 我已经更新了我的答案。请立即检查。控制器文件和视图文件有变化。
【解决方案2】:
<li>
  @foreach ($name as $retrive)
    {{ $retrive->meeting }}
  @endforeach
</li>

你没有在 foreach 中添加 @..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 2022-11-21
    • 2015-10-13
    • 2019-08-15
    相关资源
    最近更新 更多