/** * Get the route key for the model. * * @return string */ publicfunctiongetRouteKeyName() { return'username'; }
/** * Get the projects that belong to the user. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ publicfunctionprojects() { return$this->belongsToMany(Project::class, 'user_project')->withTimestamps(); }
修改 app/Project.php 檔。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/** * Get the users that belong to the project. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ publicfunctionusers() { return$this->belongsToMany(User::class, 'user_project')->withTimestamps(); }
/** * Get the environments for the project. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ publicfunctionenvironments() { return$this->hasMany(Environment::class); }
修改 app/Environment.php 檔。
1 2 3 4 5 6 7 8 9
/** * Get the project that the environments belongs to. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ publicfunctionproject() { return$this->belongsTo(Project::class); }