1

I want to retrieve all column values. Following is the dashboard controller code, which runs index method by default

<?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'));
    }
}

View File

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

It doesn't show any error or any result either

2 Answers 2

1

Can you try this?

public function fetchQuestions() {
        return questions::where('people_id','=',\Auth::guard('yourguardname')->user()->id)->get()->pluck('people_id','question');
    }
Sign up to request clarification or add additional context in comments.

1 Comment

@Jaskaran : Sorry I had written first name , instead i rectified it \Auth::guard('yourguardname')->user()->id.
0

Add ->all() after pluck

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

Though you can do it in one method:

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

4 Comments

what do you get when you dd($listQuestions)
i get this array:1 [▼ 0 => "ok dere" ] It works, but value doesn't pass or displays on the page
remove the compact and replace it with ['listQuestions'=>$listQuestions]
its throwing error Undefined variable: listQuestions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.