问题描述
我正在尝试将文档与相关文档一起存储,但我认为我正在存储一个对象但没有创建真正的关系
这是第一个模型
<?php
namespace App;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Contracts\Auth\MustVerifyEmail;
//use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Jenssegers\Mongodb\Auth\User as Authenticatable;
class User extends Authenticatable implements JWTSubject
{
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','remember_token',];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',];
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array,containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
}
这是第二个模型,与所有者上的第一个模型有关系,由字段创建
<?php
namespace App;
use Jenssegers\Mongodb\Eloquent\Model;
class Candidate extends Model
{
const UPDATED_AT = null;
public function user(){
return $this->belongsTo(User::class);
}
}
这就是我存储文档的方式
public function create(Request $request){
$owner = User::find($request->input('owner'));
$candidate = new Candidate();
$candidate->name = $request->input('name');
$candidate->source = $request->input('source');
$candidate->owner = $owner;
$candidate->created_by = auth()->user();
$candidate->save();
}
我认为它没有建立关系,这是存储的信息
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)