Laravel没有从数据库中检索值

时间:2016-10-19 14:15:09

标签: php laravel laravel-5 laravel-5.2

我想检索所有列值。以下是仪表板控制器代码,默认情况下运行索引方法

<?php

namespace App\Http\Controllers;

use App\questions;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Requests;

class Dashboard extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    public function fetchQuestions() {
        return questions::where('people_id','=',Auth::id())->pluck('question');
    }
    public function index(){
        $listQuestions=$this->fetchQuestions();
        return view('forms.question',compact('listQuestions'));
    }
}

查看档案

<ul>
@foreach ($listQuestions as $question)
    <li>{{ $question }}</li>
@endforeach
</ul>

它没有显示任何错误或任何结果

2 个答案:

答案 0 :(得分:1)

你能试试吗?

public function fetchQuestions() {
        return questions::where('people_id','=',\Auth::guard('yourguardname')->user()->id)->get()->pluck('people_id','question');
    }

答案 1 :(得分:0)

拔出后加上 - &gt; all()

return questions::where('people_id','=',Auth::id())->pluck('question')->all();

虽然你可以用一种方法做到:

public function index(){
    $listQuestions=questions::where('people_id','=',Auth::id())->pluck('question')->all();
    return view('forms.question',['listQuestions'=>$listQuestions]);
}