l5b-crud icon indicating copy to clipboard operation
l5b-crud copied to clipboard

generator plural detection error fails on special words like staff

Open bentran opened this issue 5 years ago • 9 comments

I used below command to generate a new CRUD base on the Example.

php artisan l5b:crud Staff -m

I then try to access the new CRUD using below

http://l5b.test/admin/staff and try adding a new staff

It crashed with:

` ErrorException (E_ERROR) Call to undefined method App\Models\Staff::links() (View: C:\xxx\www\l5b\resources\views\backend\staff\index.blade.php) Previous exceptions

Call to undefined method App\Models\Staff::links() (0)

` using any other words seems to work ok. Looks like somehow it is falling over with the plural detection of words like these.

using http://l5b.test/admin/staffs I get an error 404 not found.

http://l5b.test/admin/examples works no issues.

Other words / CRUD like below works no issues: php artisan l5b:crud Someones -m php artisan l5b:crud person -m

php artisan -v Laravel Framework 5.8.8

How can I bypass this issue?

Thanks.

bentran avatar Apr 23 '19 12:04 bentran

using any of the below variation of the word Staff has the same issue

MyStaff BlaStuff AllStuff

bentran avatar Apr 23 '19 12:04 bentran

Just wondering if this is a side effect of string conversion to singular & Camel case etc used bu L5BCrud?

bentran avatar Apr 23 '19 12:04 bentran

Further research brings up https://stillat.com/blog/2017/12/06/laravel-5-string-helpers-pluralization-and-strings which say the word staff is a special case. I still don't know enough to fix / by pass this issue.

bentran avatar Apr 23 '19 12:04 bentran

Actually it turns out that MyStuff, AllStaff & BlaStaff works.

I did not know that the route becomes http://l5b.test/admin/all_staffs & http://l5b.test/admin/my_staffs

bentran avatar Apr 23 '19 12:04 bentran

here is the result of generating the crud for staff

php artisan l5b:crud Staffs -m
Model Staff created successfully.

Attribute StaffAttribute created successfully.

Controller StaffController created successfully.

Repository StaffRepository created successfully.

Request ManageStaffRequest created successfully.

Request StoreStaffRequest created successfully.

Request UpdateStaffRequest created successfully.

Event StaffCreated created successfully.

Event StaffUpdated created successfully.

Event StaffDeleted created successfully.

Listener StaffEventListener created successfully.

Migration 2019_04_23_220047_create_staff_table created successfully.

Migrating table 2019_04_23_220047_create_staff_table

Routes staff created successfully.

Breadcrumbs staff created successfully.

View index.blade created successfully.

View create.blade created successfully.

View edit.blade created successfully.

View show.blade created successfully.

View deleted.blade created successfully.

View /includes/breadcrumb-links.blade created successfully.

View /includes/header-buttons.blade created successfully.

View /includes/sidebar-staff.blade created successfully.

Label backend_staff created successfully.

bentran avatar Apr 23 '19 12:04 bentran

I think I have managed to by pass the issue.

In the Doctrine Inflector package Inflectror.php

I removed the word 'staff' from the $uninflected array.

then I can do

php artisan l5b:crud staff -m

Then access the create new item by

http://l5b.test/admin/staffs/create

It then works no issues!

bentran avatar Apr 23 '19 13:04 bentran

So looks like L5B Crud is choking on generating CRUD that has 'special words' ??

bentran avatar Apr 23 '19 13:04 bentran

Hi @360col and thanks for opening this issue and solving it!

Since this is how the plural method works I will include a warning in the readme file pointing to the post in Stillat blog. I don't know if modifying the inflector package is a good idea, do you think I should mention this workaround?

pqrs avatar Apr 24 '19 19:04 pqrs

A note should be added so people don't bang their heads for days like I did. People can choose to modify the inflector package or not.

One can modify the inflector package. Generate the Crud. Then change it back. Then there would be no side effect except during that short windows they need to generate the initial L5b Crud. Also the change would get wipe out next time the inflector package gets updated.

bentran avatar Apr 26 '19 01:04 bentran