1

The database table is : prefix_adminUsers and I have a model in UserAdmin.php as below:

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class UserAdmin extends Model
{
    protected $table = 'adminUsers';
    public $timestamps = false;
}

When I tried to access the same by controller it show me the error:

Illuminate\Database\Eloquent\Builder Object ( [query:protected] => Illuminate\Database\Query\Builder Object ( [connection] => Illuminate\Database\MySqlConnection Object ( [pdo:protected] => PDO Object

my controller is as follows:

use App\Model\UserAdmin;
$userRecord = UserAdmin::where('id', '=', Auth::user()->id);
print_r($userRecord);

1 Answer 1

1

It's not an error, you are printing the eloquent class Builder, used to build the queries to retrieve the model data, but it doesn't give you the results yet because you are missing ->get() at the end.

Your code should look like:

use App\Model\UserAdmin;
$userRecord = UserAdmin::where('id', '=', Auth::user()->id)->get();
print_r($userRecord);

You can read more how to retrieve Models on the Laravel 5.5 docs.

Since each Eloquent model serves as a query builder, you may also add constraints to queries, and then use the get method to retrieve the results.

Sign up to request clarification or add additional context in comments.

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.