All Eloquent models which use SoftDeletes trait accept methods from SoftDeletingScope:
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:namespace Illuminate\Database\Eloquent {
/**
* Class Model
*
* @package Illuminate\Database\Eloquent
* @static \Illuminate\Database\Eloquent\Builder withTrashed()
* ... the rest of methods ...
*/
abstract class Model {}
}
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
namespace Illuminate\Database\Eloquent {
trait SoftDeletes {}
}
What do you think guys and especially @barryvdh ?
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
\Eloquentgenerated in_ide_helper.phpfile. 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.
Most helpful comment
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 🤷♀️