-
Notifications
You must be signed in to change notification settings - Fork 0
/
ad.php
73 lines (61 loc) · 1.67 KB
/
ad.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
<?php
/**
* Created by PhpStorm.
* User: aref
* Date: 6/11/16
* Time: 10:02 AM
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\AdImage;
use App\Comment;
class Ad extends Model
{
protected $primaryKey = "id";
protected $fillable =[
'name' , 'company','model','description' , 'price' ,'cat_id' ,'user_id'
];
public function user(){
return $this->belongsTo('App\User' ,'user_id');
}
public function ad_category(){
return $this->belongsTo('App\AdCategory' ,'cat_id');
}
public function ad_images(){
return $this->hasMany('App\AdImage');
}
public function bids(){
return $this->hasMany('App\Bid');
}
public function saveImagedata($data = ''){
$array = explode(',',$data );
$adImageModel = new AdImage();
foreach ($array as $id){
$id = trim($id);
if(empty($id))
continue;
$imageRow = $adImageModel::find($id);
$imageRow->ad_id = $this->id;
$imageRow->save();
}
}
public function getFirstImageName(){
$image = $this->ad_images()->first();
if(!$image || is_null($image))
return 'musigatedef2.png';
return $image->filename;
}
public function isBidable(){
$acceptedBid = Bid::where('ad_id','=' ,$this->id)
->where('accepted','=' ,'ACCEPTED')->get();
if(sizeof($acceptedBid)>0)
return false;
else
return true;
}
public function getComments(){
$model =new Comment();
$comments = $model->getComments($this->id ,'AD');
return $comments;
}
}