Please report back what was the issue since I can not stop thinking about it. Also mention me when you report so I do not miss it. Thanks and good luck.
it's unlikely to get the undefined variable $posts in view if you dd($post), there may some part of your code you missed out and did not show here...
as jlrdw suggested, first thing first make sure the right controller is being called before look into view, comment out all the code, just return or dd the $post...
public function indexS()
{
//$id = Auth::user()->id;
//$courses = DB::table('registered__courses')->select('user_id')->where('user_id', '=', $id)->count();
$posts = Post::all();
return $posts->all();
//return view('dashboards.student-dashboard', compact('id', 'courses', 'posts'));
}
make sure you get the posts result at this point before you proceed other debugging....
Hi @noel ,
I had a similar issue with compact recently. Replaced compact with associative array of data and it worked.
return view('dashboards.student-dashboard', ['id' => $id, 'courses' => $courses, 'posts' => $posts]);
Please let me know if this works for you. Need to investigate why compact does not work.
Hey @noel,
As far as I have seen your code, everything seems fine, there is nothing wrong in your code. Maybe you can debug your requests easily with Telescope, it's really convenient to debug every requests, Telescope will show you all parameters that have passed to your view file, also how many queries executed during request and many more. Try once, you will have your solution very easily.
Hey, as a junior developer I have been through that error alot and the only way I overcome this is by using dd(); I just die and dump at various places till I am able to find where the error is coming from.
So just take the time to dd() your code until you can find where your problem is leading from
almost certainly you are hitting different code to what you think you are. If you get the error and not the dd output then you are not reaching this controller at all.
Do you use $posts in whatever route is called when you redirect to /student ? I note you don't show the route for that, only dashboard/student
Please or to participate in this conversation.