Here is the output when i used tinker in artisan to query User Model and Team Model.
As shown in the images above User Model always return null when in fact in the database has records of user. Below is my User class
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
// use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Team;
class User extends Model implements AuthenticatableContract,
AuthorizableContract
{
use Authenticatable, Authorizable, SoftDeletes;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
protected $primaryKey = 'user_id';
/**
* The attributes that are not mass assignable.
*
* @var array
*/
protected $guarded = ['created_at','deleted_at','updated_at'];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'is_admin' => 'boolean',
'is_owner' => 'boolean',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
//protected $hidden = ['user_pass'];
public function getRememberToken()
{
return null; // not supported
}
public function setRememberToken($value){ }
public function getRememberTokenName()
{
return null; // not supported
}
/**
* Overrides the method to ignore the remember token.
*/
public function setAttribute($key, $value)
{
$isRememberTokenAttribute = $key == $this->getRememberTokenName();
if (!$isRememberTokenAttribute)
{
parent::setAttribute($key, $value);
}
}
public function isOwner()
{
return ($this->is_owner);
}
public function isAdminOrOwner()
{
return ($this->is_admin || $this->is_owner);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire