for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace NovaFlexibleContent\Layouts\LayoutTraits;
use Illuminate\Support\Str;
trait HasLayoutKey
{
/**
* The layout's unique identifier.
*/
protected ?string $key = null;
* The layout's temporary identifier.
protected ?string $_key = null;
* Retrieve the group's unique key.
public function key(): ?string
return $this->key;
}
* Retrieve the key currently in use in the views.
public function inUseKey(): ?string
return $this->_key ?? $this->key();
* Check if this group matches the given key.
public function isUseKey(string $groupKey): bool
return $this->key === $groupKey || $this->_key === $groupKey;
* Returns an unique key for this group if it's not already the case.
*
* @throws \Exception
protected function generateValidLayoutKey(string $key): string
$keyLen = 16;
if (!str_contains($key, '-')
&& strlen($key) === $keyLen) {
return $key;
// The key is either generated by Javascript or not strong enough.
// Before assigning a new valid key we'll keep track of this one
// in order to keep it usable in a Flexible::findGroup($key) search.
$this->_key = $key;
return 'c' . Str::random($keyLen-7) . date('ymd');