Laravel打印查询错误

时间:2015-08-04 06:30:15

标签: php laravel

我在路线中有这个代码:

Route::get('forum/{fname}/{fid}', 'viewForum@showForum');
控制器中的

<?php 

namespace App\Http\Controllers;
use DB;
use View;

class viewForum extends Controller 
{
    public function showForum($fname, $fid)
    {
        return View::make('forum', [
            'forums'    => DB::table('forums')
                ->where('id', $fid)
                ->where('seo-name', $fname)
                ->select()
                ->get()
        ]);
    }
}

在布局中:

@extends('layouts.main')
@section('content')
@foreach($forums as $forum)
{{ $forum->name }}
@endforeach
@stop

没关系,但是当我写错{fname}或{fid}然后没有打印,白页,但我不想显示错误,我该怎么办呢?我用viewProfile创建了它:

<?php 

namespace App\Http\Controllers;
use DB;
use View;

class viewProfile extends Controller 
{
    public function showProfile($uname, $uid)
    {
        $u = DB::table('users')
            ->where('id', $uid)
            ->where('name', $uname)
            ->first();

        return View::make('users', [
            'username'  => $u->name,
            'userid'    => $u->id,
            'email'     => $u->email,
            'regdate'   => $u->created_at
        ]);
    }
}

在此代码错误打印,但在第一个不,为什么?我该如何解决?提前致谢

我已经修好了,我刚刚添加了这段代码:

@extends('layouts.main')
@section('content')
@forelse($forums as $forum)
{{ $forum->name }}
@empty
<div class="alert alert-danger">Forum not found</div>
@endforelse
@stop

1 个答案:

答案 0 :(得分:1)

如果要显示所有错误, 在APP_ENV=local文件中设置.env。 允许/vendor/storage文件夹的递归777权限。

它应该工作.. 还要确保写入'/config/databse.php'文件'fetch' => PDO::FETCH_ASSOC,'fetch' => PDO::FETCH_CLASS,

您还应该看到DB::table('forums') ->where('id', $fid) ->where('seo-name', $fname) ->select() ->get(); 返回一个2D数组,您需要一个单维数组。 一旦您能够显示错误,您将很容易地发现所有错误。 :)