Skip to content

Commit 674a03a

Browse files
authored
Merge pull request #398 from RezaAb/master
improve addNewLink function in Link model
2 parents 7f20d27 + 52e670b commit 674a03a

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/models/Link.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Serverfireteam\Panel;
33

4+
use Carbon\Carbon;
45
use Illuminate\Database\Eloquent\Model;
56

67
class Link extends Model {
@@ -33,16 +34,31 @@ public static function getMainUrls($forceRefresh = false)
3334
}
3435
return self::$cache['main_urls'];
3536
}
37+
38+
/**
39+
* insert new link. this function don't need to use save()
40+
* @param $url
41+
* @param $label
42+
* @param $visibility
43+
* @param bool $checkExistence
44+
*/
3645
public function addNewLink($url, $label, $visibility, $checkExistence = false) // getAndSave(
3746
{
3847
if ($checkExistence && $this->isLinkExist($url, $label))
3948
{
4049
return;
4150
}
42-
$this->url = $url;
43-
$this->display = $label;
44-
$this->show_menu = $visibility;
45-
$this->save();
51+
$now = Carbon::now()->toDateTimeString();
52+
$data = array(
53+
array(
54+
'url'=>$url,
55+
'display'=>$label,
56+
'show_menu'=>$visibility,
57+
'created_at'=> $now,
58+
'updated_at'=> $now
59+
)
60+
);
61+
Link::insert($data);
4662
}
4763

4864
/**

0 commit comments

Comments
 (0)