Skip to content

Commit

Permalink
add model
Browse files Browse the repository at this point in the history
  • Loading branch information
浩王 authored and 浩王 committed Jun 25, 2017
1 parent d731aad commit 1512775
Show file tree
Hide file tree
Showing 20 changed files with 674 additions and 549 deletions.
16 changes: 15 additions & 1 deletion app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,19 @@

class Article extends Model
{
//
public function user()
{
$this->belongsTo(User::class);
}

public function tags()
{
$this->morphTo(Tag::class, 'tagsTable');
}

public function dirs()
{
$this->morphTo(DirContent::class, 'dirTable');
}
//
}
6 changes: 5 additions & 1 deletion app/Models/Dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@

class Dir extends Model
{
//
public function tags()
{
$this->morphTo(Tag::class, 'tagsTable');
}
//
}
10 changes: 9 additions & 1 deletion app/Models/DirContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@

class DirContent extends Model
{
//
public function dirTable()
{
$this->morphTo();
}

public function dir()
{
$this->belongsTo(Dir::class);
}
}
3 changes: 3 additions & 0 deletions app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

class Tag extends Model
{
public function tagsTable(){
return $this->morphTo();
}
//
}
61 changes: 42 additions & 19 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,46 @@

class User extends Authenticatable
{
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',
];
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',
];

public function articles()
{
return $this->hasMany(Article::class);
}

public function createTags()
{
return $this->hasMany(Tag::class);
}

public function dirs()
{
return $this->hasMany(Dir::class);
}

public function tags()
{
$this->morphTo(Tag::class, 'tagsTable');
}
}
Loading

0 comments on commit 1512775

Please sign in to comment.