-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPost.php
74 lines (66 loc) · 1.68 KB
/
Post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* Get all of the post's likes.
*/
public function likes()
{
return $this->morphMany('App\Like', 'likeable');
}
/**
* Eager load the likes of the post.
*
* @param \Illuminate\Database\Eloquent\Builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function laratablesQueryConditions($query)
{
return $query->with('likes');
}
/**
<<<<<<< HEAD
* Display the relationship data in custom post_liked.
=======
* Display the relationship data in custom column post_liked.
>>>>>>> d8571f20e4200599365c4017ed5519047b66a4a7
*
* @param \App\Post
* @return string
*/
public static function laratablesCustomPostLiked($post)
{
return $post->likes->implode('name', ',');
}
/**
* Display image from url in table.
*
* @param \App\Post
* @return string
*/
public static function laratablesImageUrl($post)
{
return '<img src="'.$post->image_url.'">';
}
/**
* Searching the post_liked column data.
*
* @param \Illuminate\Database\Eloquent\Builder
* @param string search term
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function laratablesSearchPostLiked($query, $searchValue)
{
return $query->orWhereHas('likes', function ($query) use ($searchValue) {
$query->where('name', 'like', "%" .$searchValue. "%");
});
}
}