Reputation: 39
I have two tables in database
I want to retrieve back comments of current logged in user in controller
Controller :
public function getIndex( Request $request )
{
$logeduser= Auth::user()->id;
$comment = DB::table('local')->select('org_id', 'comment')->where('entry_by', '=', '$logeduser')->get();
return view('dashboard.index', $comment);
}
View:
@foreach ($comment as $comm)
{{$comm->comment}}
@endforeach
it does not work without any error
Upvotes: 0
Views: 36
Reputation: 651
You must edit your controller code as given below
public function getIndex( Request $request )
{
$logeduser= Auth::user()->id;
$comments = DB::table('local')->select('comment')->where('entry_by', $logeduser)->get();
return view('dashboard.index', compact('comments'));
}
and your view must have
@foreach ($comments as $comm)
{{ $comm->comment }}
@endforeach
Upvotes: 0
Reputation: 1366
Your Query is searching in 'entry_by' for the string '$logeduser'
try this
public function getIndex( Request $request )
{
$logeduser= Auth::user()->id;
$comment = DB::table('local')->select('org_id', 'comment')->where('entry_by', '=', $logeduser)->get();
return view('dashboard.index', $comment);
}
remove the quotes around your variable
Upvotes: 1