for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace NukaCode\Menu\Traits;
/**
* Class Insertable
*
* @package NukaCode\Menu\Traits
*/
trait Insertable {
* Let the add method know not to append this item as it was spliced into the array.
* @var bool
public $insert = false;
* Insert this item after another item in the menu
* @param $slug
public function insertAfter($slug)
{
$this->insertObject($slug, true);
}
* Insert this item before another item in the menu
public function insertBefore($slug)
$this->insertObject($slug);
* @param $after
private function insertObject($slug, $after = false)
$this->insert = true;
foreach ($this->menu->links as $linkKey => $link) {
if ($link->isDropdown()) {
foreach ($link->links as $subLinkKey => $subLink) {
if ($subLink->slug == $slug) {
if ($after) {
$link->links->splice($subLinkKey + 1, 0, [$this]);
} else {
$link->links->splice($subLinkKey, 0, [$this]);
if ($link->slug == $slug) {
$this->menu->links->splice($linkKey + 1, 0, [$this]);
$this->menu->links->splice($linkKey, 0, [$this]);