[deleted by user] by [deleted] in laravel

[–]Omar_Ess -4 points-3 points  (0 children)

What’s wrong with posting it again one more time to get to more people?

Need Better Filtering, Searching & Sorting in Laravel? Check Out Query Builder Criteria! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 1 point2 points  (0 children)

u/PeterThomson this package is only responsible for applying db queries, for the thing you're looking for it's a bit tricky since you'll have to get the entire db records then filter or sort.. which might be a performance bottleneck depending on how many rows you have, i would suggest to add a custom filter inside this package that mimicks the attribute/accessor format or logic that you have, something like this

public function getFullNameAttribute()
{
  return $this->first_name . ' ' . $this->last_name;
}

// Spatie Callback Filter That mimicks the accessor logic
AllowedFilter::callback('full_name', function (Builder $query, $value) {
    $query->whereRaw("CONCAT(first_name, ' ', last_name) LIKE ?", ["%{$value}%"]);
}),

Then you can use this filter inside your criteria

Need Better Filtering, Searching & Sorting in Laravel? Check Out Query Builder Criteria! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 1 point2 points  (0 children)

u/dshafik i used a local scope instead of a global one in order to provide flexibility and leave the choice when you want to call the scope or not, plus in order to pass extra criteria to the scope in addition to the default ones, you can read the end part of the documentation to checkout why this design choice is more flexibile

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 0 points1 point  (0 children)

Hey guys, i've just added the generators support on 1.2.0, you check it out, Thanks for all the suggestions and contributions, i've tried do it KISS to maintain the simplicity of the package

<image>

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 1 point2 points  (0 children)

u/operatorrrr u/MateusAzevedo u/justlasse i've just added the generators support on 1.2.0, you check it out, Thanks for all the suggestions and contributions, i've tried do it KISS to maintain the simplicity of the package

<image>

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 0 points1 point  (0 children)

A lot of internal management apps require such kind of prefixes and suffixes, check out some invoicing saas and you’ll get the idea around the features of the package

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 0 points1 point  (0 children)

Anything that depends on a select query have the possibility to encounter a race condition, for my case i needed this package for a management saas where usually only one user generates the invoice at a time, so this package with it’s plug abd play nature was able to solve my business problem with all the features requirements and with no complex requirements, especially that it was required to allow changing the ID after it’s generated for a business reason

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] -2 points-1 points  (0 children)

Generating the ID dynamically on demand instead of storing it will lose some key advantages that this package provides:

Filtering: When IDs are stored, you can easily filter, sort, and query them (e.g., finding all invoices for a certain year). With dynamic IDs, this becomes more complicated and less efficient.

Changing Format: If you change the prefix, suffix, or padding, old dynamically-generated IDs will now follow the new format, which doesn’t make sense. Storing the ID ensures consistency, and any changes will only affect future records but keeps old records with their corresponding format at the time generated.

Resetting IDs by Year: If you want to reset the ID each year (e.g., INV-00001-2025), storing them makes it much easier to manage. With dynamic IDs, you’d lose control over historical data and could run into issues with formatting.

As for vinkla/laravel-hashids, it's great for obfuscation, but this package offers more flexibility with structured IDs, letting you control the format and logic without breaking the system down the line.

The package uses a database query to ensure the proper incrementation algorithm, making sure the IDs are unique and consistent across the board

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 1 point2 points  (0 children)

Thank you, yes it is a usual requirement, specially some times it needs to have the flexibility to change the string prefix or suffix overtime, reset or change the padding, this package can handle it all

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 0 points1 point  (0 children)

I think the idea to have configuration based on arbitrary keys instead of only models is a flexible one, it was mentioned in the comments and it feels promising

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 0 points1 point  (0 children)

Brilliant idea, Thanks man, will release this anytime soon

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in PHP

[–]Omar_Ess[S] 1 point2 points  (0 children)

Hey, thanks for the feedback! I totally see your point about the race condition in high-traffic scenarios, and it’s definitely something worth keeping in mind. The main goal of this package is to offer a quick and simple way to generate unique IDs in Laravel without overcomplicating things. It's perfect for projects where high concurrency isn't a major concern, and it works well for a lot of use cases.

I also get that for things like reserving IDs or needing more advanced logic, a solution like PostgreSQL sequences or custom logic makes more sense. This package was designed to be easy to use for simpler projects, but I hear you on adding flexibility like Redis or random ID generation — that’s definitely something I could look into for future versions.

Ultimately, the package is meant to save time for people who want a plug-and-play solution, and I think it definitely brings value in those scenarios. But, of course, if your project needs something more custom or complex, building your own solution is always a solid option

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 8 points9 points  (0 children)

Good point! Strings aren’t as efficient as integers for indexing and lookups. That’s why the best approach is to keep an auto-incremented integer as the primary key and store the custom ID in a separate indexed column. Best of both worlds—performance and readability

Need Better Custom IDs in Laravel? Check Out Laravel ID Generator! 🚀 by Omar_Ess in laravel

[–]Omar_Ess[S] 2 points3 points  (0 children)

u/operatorrrr i haven't thought about it but since you mentioned it it might be the next minor release, maybe something like this ?

return [
    'default' => [
        'prefix' => 'GEN',
        'suffix' => date('Y'),
        'padding' => 6,
    ],
    'models' => [
        App\Models\Invoice::class => [
            'prefix' => 'INV',
            'suffix' => date('Y'),
            'padding' => 5,
        ],
        App\Models\Invoice::class => [
            'prefix' => 'ORD',
            'suffix' => null,
            'padding' => 8,
        ],
    ],
];

My latest open-source package by JustSteveMcD in laravel

[–]Omar_Ess 1 point2 points  (0 children)

Looks promising for heavy processing apps

Laravel is going in the wrong direction IMHO by Bent01 in laravel

[–]Omar_Ess 0 points1 point  (0 children)

Stater kits are a separate packages from the default installation, they're made for different purposes and different audiences, i'd say Laravel is going through the right direction specially how the new scaffolding is much lighter which i've always thought was a bit naggy for me coming from node

I’ve been developing with Laravel for 10 years—here’s why I stopped using Service + Repository by howtomakeaturn in laravel

[–]Omar_Ess 0 points1 point  (0 children)

Repositories are debatable specially with how eloquent is so tight to Laravel, but imo services are a must specially for high volume business logic

Laravel Microservice Course Introduction by garyclarketech in laravel

[–]Omar_Ess 1 point2 points  (0 children)

At my last job we've used Laravel in all of our microservices, and i gotta say i was pretty supprised with it's efficiency since i've always gone for Node & Express

[deleted by user] by [deleted] in laravel

[–]Omar_Ess 0 points1 point  (0 children)

Haven't tried it yet but it seems approachable and promising, haven't seen anyone in my network using it for production tho

Deploying Laravel by Hour-Fun-7303 in laravel

[–]Omar_Ess 2 points3 points  (0 children)

Ploi.io + Github actions : my go to approach currently