troubleshooting Question

How do I display and update a row in the context of a JOIN written using Laravel's Eloquent?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
8 Comments1 Solution27 ViewsLast Modified:

Here's my URL:

Here's my Route: Route::get('/show/cuser/{id}', 'CUserController@show')->name('adminShowCUser');

Here's my Controller: 

    public function show($id)
      $pro = CeuUser::findOrFail($id);
      return view('admin/showCuser', compact('pro'));

...and here's what the page looks like:

The challenge is this: I need to be able to display and edit the results of the quiz attached to the course content the user has ordered. 

On the "list" of orders, that information is displayed and when you look at the query that's running in the background, it looks like this:

$users = CeuUser::leftJoin('ceu_results', 'ceu_users.sid', '=', 'ceu_results.sid')->select('ceu_users.*','ceu_results.quiz_date','ceu_results.status','ceu_results.attempts','ceu_results.pass')->orderBy('name', 'asc')->get();
      return view('admin/listCusers', compact('users'));

I need to incorporate something similar when I display a single student, in that I've got to do a JOIN on the "ceu_results" table on the "sid" value.

Here's a screenshot of the ceu_results table:

How do I do a JOIN with a condition, the condition being the ID of the student in question?

And then once I've got the quiz results displayed, how do I update the "status" in the "ceu_results" table? 

This is an example of an UPDATE function on the current Controller...

 public function update(Request $request)
         //update ceu_users table
         $success='User was successfully updated!';
         if($customer->save()) {
            Session::flash('message', 'Window closed successfully updated.');
            return redirect('/admin/show/cuser/'.$request->the_id);

How do I tweak that philosophy / approach in a way where I can update two tables?

I imagine I'll need the sid value, but how do I pass that into the function?

Simple questions, but I'm a simple man! 

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros