pqrs / l5b-crud

CRUD artisan command for rappasoft/laravel-5-boilerplate
21 stars 15 forks source link

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

Open bentran opened 5 years ago

bentran commented 5 years ago

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 commented 5 years ago

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

MyStaff BlaStuff AllStuff

bentran commented 5 years ago

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

bentran commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

pqrs commented 5 years ago

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 commented 5 years ago

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.