我正在开发一个基于 Web 的应用程序,技术堆栈是:VueJS,用于表示层,Laravel(PHP)用于RESTFUL API服务,以及一个名为neo4j 的基于 nosql 图的数据库 。这是问题上下文,我有一个名为Post的模型,此处定义的属性共享所有帖子类型,因此它们都将拥有它:
use NeoEloquent;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use Vinelab\NeoEloquent\Eloquent\SoftDeletes;
class Post extends NeoEloquent
{
protected $label = 'Post';
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'slug',
'body',
'status',
'image',
'published_at',
'read_time',
'isModerate',
'link',
'external_id'
];
/**
protected $hidden = ['remember_token'];
/**
* relations
*/
public function authors()
{
return $this->belongstoMany('App\User', 'AUTHOR');
}
public function getSlugOptions(): SlugOptions
{
return SlugOptions::create()->generateSlugsFrom('title')->saveSlugsTo('slug');
}
//Post type
public function contentType(){
return $this->hasOne('App\ContentType','IS_OF_TYPE');
}
}
PostType:这里的类型可以是文件、链接、事件等。例如:[name=>'Event','description'=>'description','slug'=>'event']
class PostType extends NeoEloquent
{
protected $label='ContentType';
protected $dates=['created_at','updated_at','deleted_at'];
protected $fillable=[
"name",
"description",
"slug"
];
//Ce input contentype sera associe a plusieurs input fields
public function customFields(){
return $this->belongsToMany('App\CustomField',"HAS_FIELD");
}
public function post(){
return $this->belongsToMany('App\Post','IS_OF_TYPE');
}
}
最后是CustomField模型:
class CustomField extends NeoEloquent
{
protected $label="CustomType";
protected $dates=["created_at","updated_at","deleted_at"];
protected $fillable=[
"field_name",
"field_type",
"field_order",
"validation_rules"
];
public function contentTypes(){
return $this->belongsToMany('App\CustomField','HAS_FIELD');
}
}
翻阅古今