Laravel-ide-helper: "SoftDeletingScope" methods in all Eloquent Models

Created on 5 Dec 2016  ·  7Comments  ·  Source: barryvdh/laravel-ide-helper

All Eloquent models which use SoftDeletes trait accept methods from SoftDeletingScope:

  1. forceDelete
  2. restore
  3. withTrashed
  4. withoutTrashed
  5. onlyTrashed

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.

  1. Explicitly add a blank 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 {}
}
  1. 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.

  2. Add this PHPDoc with artifical blank trait

namespace Illuminate\Database\Eloquent {
    trait SoftDeletes {}
}

What do you think guys and especially @barryvdh ?

stale

Most helpful comment

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 🤷‍♀️

All 7 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcus-clements picture marcus-clements  ·  3Comments

Gummibeer picture Gummibeer  ·  3Comments

half-evil picture half-evil  ·  3Comments

ghost picture ghost  ·  5Comments

Newbie012 picture Newbie012  ·  4Comments