for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Fomvasss\SlugMaker\Models;
trait SlugModelScopesTrait
{
public function scopeByTypesByNames($query, array $attributes)
foreach ($attributes as $type => $slugs) {
if (! empty($slugs)) {
$names = is_array($slugs) ? $slugs : [$slugs];
$query->orWhere('slugable_type', $type)->whereIn('name', $names);
}
return $query;
public static function getArrayIdsByTypesByNames(array $attributes): array
return self::byTypesByNames($attributes)->pluck('slugable_id')->toArray();
public static function getGropedArrayIdsByTypesByNames(array $attributes): array
$slugs = self::byTypesByNames($attributes)->pluck('slugable_type', 'slugable_id');
return self::groupByType($slugs);
private static function groupByType($slugs): array
$res = [];
foreach ($slugs as $id => $type) {
$res[$type][] = $id;
return $res;