orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
138 stars 34 forks source link

"Resource" is indiscriminately removed from Resource title #39

Closed ozthegreat closed 3 years ago

ozthegreat commented 3 years ago

Hi

I have my own Model type called "Resource", making the Orchid-Crud class "ResourceResource". The page title doesn't show though because the nameWithoutResource class strips the word "Resource" from everywhere in the class name, not just the end. I better solution would be replacing this line: https://github.com/orchidsoftware/crud/blob/ae8c6615c48b4e5b0afd537b62f73cc03aa2b8f9/src/Resource.php#L140

with something like (assuming they always end in "Resource"): return substr(Str::of(class_basename(static::class)), 0, -8);

tabuna commented 3 years ago

Hi you can also just override this method:

    /**
     * @return string
     */
    public static function nameWithoutResource(): string
    {
        return class_basename(static::class);
    }
ozthegreat commented 3 years ago

Yep that's what I did. Just thought I'd raise a PR to contribute back. Great software, thanks very much!!

tabuna commented 3 years ago

You can contribute. Let's make a straightforward construction:

return Str::of(class_basename(static::class))->replace('Resource', '')->whenEmpty(function () {
    return 'Resource';
});

Maybe this is a little illogical, but it will work without exclusions for going beyond the limits of characters. What do you think?

ozthegreat commented 3 years ago

Looks good!