src/Database/Concerns/IsRole.php
protected function findOrCreateRolesByName($names)
    {
        if (empty($names)) {
            return [];
        }

        $existing = static::whereIn('name', $names)->get()->keyBy('name');

        return (new Collection($names))
                ->diff($existing->pluck('name'))
                ->map(function ($name) {
                    return static::create(compact('name'));
                })
                ->merge($existing);
    }
protected function findOrCreateRolesByName($names)
    {
        if (empty($names)) {
            return [];
        }

        $existing = static::whereIn('name', $names)->get()->keyBy('name');

        return (new Collection($names))
                ->diff($existing->pluck('name'))
                ->map(function ($name) {
                    return static::create(compact('name'));
                })
                ->merge($existing);
    }
protected function findOrCreateRolesByName ( $ names ) { if ( empty ( $ names ) ) { return [ ] ; } $ existing = static :: whereIn ( 'name' , $ names ) -> get ( ) -> keyBy ( 'name' ) ; return ( new Collection ( $ names ) ) -> diff ( $ existing -> pluck ( 'name' ) ) -> map ( function ( $ name ) { return static :: create ( compact ( 'name' ) ) ; } ) -> merge ( $ existing ) ; }
Find roles by name, creating the ones that don't exist.

@param  iterable  $names
@return \Illuminate\Database\Eloquent\Collection
Find roles by name creating the ones that don t exist .