Reputation: 351
I want to add a custom inflection to Laravel. In Rails this wasn't that hard to do, but I cannot seem to find an answer on how to do it in Laravel.
How do I add my own inflection to Laravel?
Upvotes: 0
Views: 817
Reputation: 21
This no longer works for current Laravel. Now you have to write:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Doctrine\Common\Inflector\Inflector;
class PluralizationServiceProvider extends ServiceProvider {
public function register()
{
Inflector::rules('plural', ['irregular' => ['octopus' => 'octopi']]);
}
}
Upvotes: 2
Reputation: 15
It is also necessary add the providers folder to your composer autoload.
"autoload": {
"classmap": [
...
"app/providers"
]
},
Upvotes: 0
Reputation: 87779
Probably doing:
Illuminate\Support\Pluralizer::$irregular['subscribe'] = 'subscribes';
Best place to load it is a Service Provider:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Pluralizer;
class PluralizationServiceProvider extends ServiceProvider {
public function register()
{
Pluralizer::$irregular['octopus'] = 'octopi';
}
}
And load it in your app/config/app.php:
'App\Providers\PluralizationServiceProvider',
Upvotes: 2