Closed Stalinko closed 3 years ago
Duplicate of https://github.com/barryvdh/laravel-ide-helper/issues/371 but really needed.
Any Solution for withTrashed() on relationship?
Exception: Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsTo::withTrashed()
Could not analyze class App\Order.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.
The issue is still present on the latest version.
Any updates?
Add this PHPDoc before
\Eloquent
generated in_ide_helper.php
file. Though I don't know if there is a good way if implementing this.
I did not look into this in detail but this suggestion make sense to me and AFAIK there's precedence. So, don't take my word for gold, but if it's about a) detecting the trait and b) just adding the static phpdoc method and slap a test on it, would this be a satisfying solution?
I think PRs are welcome 🤷♀️
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.
For getting the static methods to autocomplete on the model, like User::withTrashed()->get()
, nothing is needed. The trait now includes the methods in its docblock header.
But using the methods on relationship methods like $user->posts()->withTrashed()->get()
is still not possible. I've had partial success adding this to _ide_helper.php
:
namespace Illuminate\Database\Eloquent\Relations {
/**
* @method \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withTrashed()
* @method \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder onlyTrashed()
* @method \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withoutTrashed()
*/
class Relation {}
}
This stops the complaints about unknown methods, but it still won't autocomplete them (using PhpStorm.)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.
Any updates?
Any updates? @barryvdh isn't around?
Any pull requests?
5 years have passed, I think now I've grown enough to make a good PR, will try to do that in the nearest time 😊
I'm running into this issue on the latest version of everything. Is there something I should be enabling to resolve it?
Yea, same here. I can comfirm.
All Eloquent models which use
SoftDeletes
trait accept methods fromSoftDeletingScope
:Usage example:
InventoryItem::withTrashed()->where('unit_id', $unit->id)->update(['unit_id' => 1]);
Equipment::where('name', 'Stick')->onlyTrashed()->all();
Currently Laravel doesn't provide any way to typehint these methods in PHPStorm (and other smart IDEs if any...). We can solve this in ide-helper. I have some ideas how to do this, but I want to discuss with you which is better.
Illuminate\Database\Eloquent\Model
class with PHPDoc where these methods described like:Add this PHPDoc before
\Eloquent
generated in_ide_helper.php
file. Though I don't know if there is a good way if implementing this.Add this PHPDoc with artifical blank trait
What do you think guys and especially @barryvdh ?