laravel-id-generator | Easy way to generate custom ID | Database library
kandi X-RAY | laravel-id-generator Summary
kandi X-RAY | laravel-id-generator Summary
Easy way to generate custom ID from database table in Laravel framework.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Generate a unique ID
- Get field type
- Boot the IDatable trait .
- Validate ID config
- Bootstrap the application .
- Register the id generator .
laravel-id-generator Key Features
laravel-id-generator Examples and Code Snippets
Community Discussions
Trending Discussions on laravel-id-generator
QUESTION
I'm trying to make my custom ID for table posts
. And I found haruncpi laravel id generator and I installed it with this command.
composer require haruncpi/laravel-id-generator
.
After that I add use Haruncpi\LaravelIdGenerator\IdGenerator;
to my PostsController
. And now i need to add this snippet to my model.
$id = IdGenerator::generate(['table' => 'posts', 'length' => 10, 'prefix' =>'INV-']);
But I don't know where and how... Maybe in public function store()
or somewhere else? Please help!
I just want my id to be like:
INV-000001
INV-000002
...
ANSWER
Answered 2020-Jan-04 at 00:47Laravel models has a boot()
method, where you can register calls related to your model. Therefor you can subscribe to the creating event, which will fire before the model is saved and you can mutate the model in the process.
So in your Post.php model, add the following.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install laravel-id-generator
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page