mardi 19 juin 2018

ORM not working in Default UserController & User Model in laravel

I want to get User wise Role. here is I'm facing error ....

UserController.php ( user controller file )

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\UserRequest;
use App\Employee;
use App\Role;
use App\User;
use App\Site;
use App\Client;
use App\ProjectType;
use App\UserPermission;
use Auth;
use DB;
use App\Project;

class UsersController extends BaseController {

public function __construct() {
    $this->isSetClientAndProjectType();

    $data = User::with('Role')->first();        
    echo "<pre>";print_r(json_decode($data)); die;

    }
}

User.php ( user model file )

namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Authenticatable {

use SoftDeletes;

 use Notifiable;

protected $fillable = [
    'name', 'role_id', 'password', 'siteid', 'email', 'status', 'allowed_to_bypass_pm', 'allowed_to_bypass_admin'
];
protected $hidden = [
    'password', 'remember_token',
];

// Get users roles
public function Role() {
    return $this->hasMany('App\Role', 'role_id', 'id');
 }
}

Error is

enter image description here

How can i solve this error?

Help me guys.

Thank You.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire