Content::comments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Content extends Model
8
{
9
    /**
10
     * The attributes that are mass assignable.
11
     *
12
     * @var array
13
     */
14
    protected $fillable = [
15
        'title', 'text', 'image', 'link', 'published_at'
16
    ];
17
    
18
    /**
19
     * Content belongsTo .
20
     *
21
     * @return \Illuminate\Database\Eloquent\Relations\belongsTo
22
     */
23
    public function user()
24
    {
25
    	return $this->belongsTo('App\User');
26
    }
27
  
28
    /**
29
     * Content belongsToMany .
30
     *
31
     * @return \Illuminate\Database\Eloquent\Relations\belongsToMany
32
     */
33
    public function likes()
34
    {
35
    	return $this->belongsToMany('App\User', 'likes', 'content_id', 'user_id');
36
    }
37
  
38
    /**
39
     * Comment has many .
40
     *
41
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
42
     */
43
    public function comments()
44
    {
45
        // hasMany(RelatedModel, foreignKeyOnRelatedModel = user_id, localKey = id)
46
        return $this->hasMany(Comment::class);
47
    }
48
  
49
    public function getPublishedAtAttribute($value)
50
    {
51
      $data = date('H:i d/m/Y', strtotime($value)); 
52
      return str_replace(':', 'h', $data);
53
    }
54
}
55