Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator plural detection error fails on special words like staff #9

Open
bentran opened this issue Apr 23, 2019 · 9 comments
Open

Comments

@bentran
Copy link

bentran commented Apr 23, 2019

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
Copy link
Author

bentran commented Apr 23, 2019

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

MyStaff
BlaStuff
AllStuff

@bentran
Copy link
Author

bentran commented Apr 23, 2019

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

@bentran
Copy link
Author

bentran commented Apr 23, 2019

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 bentran changed the title generator pliral detection error generator plural detection error Apr 23, 2019
@bentran
Copy link
Author

bentran commented Apr 23, 2019

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
Copy link
Author

bentran commented Apr 23, 2019

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
Copy link
Author

bentran commented Apr 23, 2019

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
Copy link
Author

bentran commented Apr 23, 2019

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

@bentran bentran changed the title generator plural detection error generator plural detection error fails on special words like staff Apr 23, 2019
@pqrs
Copy link
Owner

pqrs commented Apr 24, 2019

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?

@bentran
Copy link
Author

bentran commented Apr 26, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants