1
votes

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

1 Answers

1
votes

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.