Laravel-Backpack / devtools-issues

Bug reports and feature requests for our closed-source DevTools package
4 stars 1 forks source link

[Bug] failed to open stream: No such file or directory when creating new model #17

Closed malle-pietje closed 3 years ago

malle-pietje commented 3 years ago

Bug report

What I did

I initially created a model (Customer) that I wanted to redo using the DevTools so I deleted all the generated files. I then tried to create a new version of the model.

PS: it's a pity you cannot modify an existing model using DevTools

What I expected to happen

The new model and its files are created.

What happened

An Exception is thrown:

include(/home/erik/laravel/customers/ICT-Web-Solution/admin_gen2/vendor/composer/../../app/Models/Customer.php): failed to open stream: No such file or directory

What I've already tried to fix it

Retried multiple times, restarted web server, changed browser, no idea what else to do.

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 7.4.9 (cli) (built: Jul 5 2021 13:33:00) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies

LARAVEL VERSION:

v8.67.0@fc52acafd069aedc079bf8f17d1a4af4ef489b1e

BACKPACK VERSION:

4.1.57@7996979454fb7e02a866ee56dd7569f7d35f5ded

Operating System and Server Setup

I encountered the problem above on my Ubuntu 20.04 machine, and my web server is set up using the LAMP stack.

tabacitu commented 3 years ago

Hi @malle-pietje ,

Thanks for taking the time to submit this!

Let me make sure I understand correctly what happened. Was it

Process A)

(or maybe)

Process B)

If it's Process B, I suspect the problem is that... there is not Customer model at this point. You shouldn't have seen it in the table, since you just deleted it. The only way to re-generate everything should be to do that from the migration - to generate both a Model and the associated files. If you run composer dump-autoload after deleting everything... do you still see it in your table?


If this indeed what happened (Process B), what I think we can do right now, to prevent this frustration in the future:

Then in the not-too-distant future we should:

Of course, the last one has enormous implications, because the dev might have modified the files already, and we don't want them to lose all their changes. But at first... we could just tell the dev "We're going to overwrite the files x, y, z and you'll lose any changes you made. Are you ok with that?" then in the future maybe we will might be able to let him pick the files, or see the diffs, or something like that (even more difficult). Note to self - to achieve even the basics of this (overwriting) we need to store the resulting JSON somewhere... probably in storage/backpack/devtools/migrations and storage/backpack/devtools/models.

PS: it's a pity you cannot modify an existing model using DevTools

I agree, we want that too, but it's a HUGE undertaking like mentioned above. We'll do it! But it'll take some time to do it right.

Sorry for the long reply. Could you please confirm it was Process (A) or Process (B) or something else?

malle-pietje commented 3 years ago

Hi @tabacitu , thanks for the reply. This error occurred after following Process A, after also deleting the route and the entry in the sidebar.

promatik commented 3 years ago

I tried to replicate this, but I never got the error 😔

This is super strange because there's a validation when creating the Model;

if (class_exists("App\\Models\\$model")) {
    $validator->errors()->add('name', "The $model model already exists.");
}

@tabacitu what if we had a delete button on Models, for situations like this, it's not a fix for this issue, it's more like a feature. It could ask if the user wanted to delete everything associated with the Model – Controller, Request, Migrations, Seeder, Factory ...

malle-pietje commented 3 years ago

@promatik I've tried to replicate this with other models but wasn't able to do so. I agree that a delete option (for all associated stuff or selectively) would be useful.

tabacitu commented 3 years ago

A Delete option should would be useful in this case, I agree.

Let's do it. I've added issue https://github.com/Laravel-Backpack/DevTools/issues/264 for this.

tabacitu commented 3 years ago

I'm going to close this - we've added an issue to create a Delete button, that should make this experience a lot better. If anybody else gets this problem please post your experience here and we'll reopen 🙏

AxelGanter commented 1 year ago

same problem here

Return type of Backpack\DevTools\CustomFile::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/username/laravelproject/vendor/backpack/devtools/src/CustomFile.php on line 373

AxelGanter commented 1 year ago

I quess its some kind of cache somewhere .... ?

test with an incognito browser failed as well restarting artisan serve did not help

php artisan cache:clear did also NOT work