1

I had used a custom query in my controller in laravel here is my code in my controller:

public function c_viewSystemUser()
{
    $title = "View System Users";

    $jSu = DB::select(DB::raw("SELECT dbo_systemusers.SystemUserID,dbo_systemtypes.SystemType, dbo_systemusers.SystemUserName INNER JOIN dbo_systemtypes ON dbo_systemusers.SystemUserTypeID = dbo_systemtypes.SystemUserTypeID"));

    return View::make('ssims.view_systemUser',compact('title','jSu'));
}

I wanted to display its result in my blade file view_systemUser

here is my code inside the view:

@if ($jSu)

<table class="table table-striped table-hover" id="detailTable">
    <thead>
        <tr>
            <th>System User ID</th>
            <th>SystemUser Type ID</th>
            <th>System UserName</th>
            <th>System User Description</th>
        </tr>
    </thead>

    <tbody>
        @foreach ($jSu as $vu)
            <tr>

                    <td>{{ $vu->dbo_systemusers.SystemUserID }}</td>
                    <td>{{ $vu->dbo_systemtypes.SystemType }}</td>
                    <td>{{ $vu->dbo_systemusers.SystemUserName}}</td>
                    <td>{{ $vu->dbo_systemusers.SystemUserDescription}}</td>
            </tr>
        @endforeach

    </tbody>

</table>

And I am having an error:

Undefined property: stdClass::$dbo_systemusers (View: C:\xampp\htdocs\laravel3\app\views\ssims\view_systemUser.blade.php)

Any suggestions?

4
  • im fairly new to laravel 4.2 sorry if i had a lot of question lately Commented Sep 20, 2015 at 8:57
  • Can i see the output of print_r($jSu);? Commented Sep 20, 2015 at 8:59
  • i tried removing the table then added print_r($jSu) heres what i got Array ( [0] => stdClass Object ( [SystemUserID] => 1 [SystemType] => admin [SystemUserName] => 11388242 [SystemUserDescription] => This is me, shamvil ) Commented Sep 20, 2015 at 9:05
  • Try my answer. You don't use . dot notation Commented Sep 20, 2015 at 9:07

2 Answers 2

2

Try this:

@foreach ($jSu as $key => $vu)
   <tr>

      <td>{{ $vu->SystemUserID }}</td>
      <td>{{ $vu->SystemType }}</td>
      <td>{{ $vu->SystemUserName}}</td>
      <td>{{ $vu->SystemUserDescription}}</td>
   </tr>
@endforeach
Sign up to request clarification or add additional context in comments.

1 Comment

No prob. :D Glad could help you
1

You forgot to join dbo_systemusers with dbo_systemtypes. Try this code

SELECT dbo_systemusers.SystemUserID,dbo_systemtypes.SystemType, dbo_systemusers.SystemUserName from dbo_systemusers INNER JOIN dbo_systemtypes ON dbo_systemusers.SystemUserTypeID = dbo_systemtypes.SystemUserTypeID

And Try this on View page

 @foreach ($jSu as $vu)
        <tr>

                <td>{{ $vu->SystemUserID }}</td>
                <td>{{ $vu->SystemType }}</td>
                <td>{{ $vu->SystemUserName}}</td>
                <td>{{ $vu->SystemUserDescription}}</td>
        </tr>
    @endforeach

Comments

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.