如图所示,withTrashed方法没有代码提示。
![]()
关于软删除的部分,可以参考laravel的文档:传送门,主要影响了trashed
、restore
、withTrashed
、withoutTrashed
、onlyTrashed
这5个方法。
withTrashed、withoutTrashed、onlyTrashed的代码提示
在对应的Model里添加下面的phpDoc方法注释来解决:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?php
namespace App\Model;
use Hyperf\Database\Model\SoftDeletes;
class Test extends Model { ... }
|
2021.4.1更新 trashed、restore的代码提示
发现phpDoc有个@mixin
,可以直接把对应类的方法添加到当前类的代码提示中,现在改为:
对应模型类中增加@mixin SoftDeletes
注释
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?php
namespace App\Model;
use Hyperf\Database\Model\SoftDeletes;
class Test extends Model { use SoftDeletes;
其他代码... }
|
在使用的位置用@var
注释
1 2 3 4 5 6 7 8 9 10 11
| <?php
$test = Test::withTrashed()->find(1);
if ($test->trashed()) { $test->restore(); }
|
终于解决啦,还是对phpDoc不熟啊。