Laravel BelongsTo关系在部署后不起作用,但在本地计算机中起作用

时间:2019-07-17 13:43:39

标签: php laravel eloquent

我正在使用下面的模型,它在我的机器上正常工作,但是在将其部署到生产环境后,它返回的是null而不是数据用户。



    namespace App;
    use Illuminate\Support\Facades\DB;

    use Illuminate\Database\Eloquent\Model;

    class Occurrence extends Model {
       protected $table      = 'occurrences';
       protected $guarded    = [];
       protected $primaryKey = 'id_occurrence';

       public function owner(){

          return $this->belongsTo(User::class, 'id_user_fk', 'id_user');

       }

       public function department(){

          return $this->belongsTo(Department::class, 'id_department_fk', 'id_department');

       }
    }

这两种方法都在我的本地计算机上运行。



    $occurrence = new App\Occurrence;
    => App\Occurrence {#2938}
    >>> $occurrence->first()->owner;
    => App\User {#2947
         id_user: 2,
         name: "Jiripoqueiro",
         email: "jiripoca_vaipiar@yahoo.com.br",
         dateofbirth: "1985-08-15",
         active: 1,
         created_at: "2019-06-03 12:05:50",
         updated_at: "2019-06-03 12:05:50",
       }

但是当我部署它时,“所有者”方法返回null。



    >>> $occurrence = new App\Occurrence;
    => App\Occurrence {#2970}
    >>> $occurrence->first()->owner;
    => null

这很奇怪,因为与“部门”方法的belongTo关系在开发和生产两种情况下都有效,但所有者方法却没有。

请参阅下面的User类



    namespace App;

    use Illuminate\Notifications\Notifiable;
    use Illuminate\Foundation\Auth\User as Authenticatable;

    class User extends Authenticatable
    {
       //protected $guarded = [];
       protected $primaryKey = 'id_user';
       use Notifiable;


        /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable = [
            'name', 'email', 'password',
        ];

        /**
         * The attributes that should be hidden for arrays.
         *
         * @var array
         */
        protected $hidden = [
            'password'
        ];
    }

谢谢!

0 个答案:

没有答案