Skip to content

Commit

Permalink
Merge pull request #398 from RezaAb/master
Browse files Browse the repository at this point in the history
improve addNewLink function in Link model
  • Loading branch information
AlirezaAlgo authored Jun 26, 2019
2 parents 7f20d27 + 52e670b commit 674a03a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/models/Link.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Serverfireteam\Panel;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Link extends Model {
Expand Down Expand Up @@ -33,16 +34,31 @@ public static function getMainUrls($forceRefresh = false)
}
return self::$cache['main_urls'];
}

/**
* insert new link. this function don't need to use save()
* @param $url
* @param $label
* @param $visibility
* @param bool $checkExistence
*/
public function addNewLink($url, $label, $visibility, $checkExistence = false) // getAndSave(
{
if ($checkExistence && $this->isLinkExist($url, $label))
{
return;
}
$this->url = $url;
$this->display = $label;
$this->show_menu = $visibility;
$this->save();
$now = Carbon::now()->toDateTimeString();
$data = array(
array(
'url'=>$url,
'display'=>$label,
'show_menu'=>$visibility,
'created_at'=> $now,
'updated_at'=> $now
)
);
Link::insert($data);
}

/**
Expand Down

0 comments on commit 674a03a

Please sign in to comment.