I have a system which includes a lot of user. A user has a project, if the admin deleted the user from User's table, project created and user should still be indicated as author. Already added deleted_at on the users table and added soft delete to User Model, still no luck.
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends \TCG\Voyager\Models\User
{
use HasApiTokens, Notifiable, SoftDeletes;
protected $dates = ['deleted_at'];
Did you add withTrashed() to belongsTo relationship?
Did you add withTrashed() to belongsTo relationship?
@MrCrayon
I didn't. Is it needed to add ?
btw, It's the default user model I'm using .
As per Laravel documentation, yes.
https://laravel.com/docs/5.8/eloquent#soft-deleting
@MrCrayon
Sorry sir, but I think you're talking about retrieving the trashed data.
My problem is the data is not being soft deleted.
Maybe rephrase your issue because that's what it sounds like, if user is deleted and not soft deleted then that's the problem I would not even mention any other relationship where the user doesn't show up :wink:
Also if this is the problem it should be marked as possible BUG not feature.
Anyway I just tried on a fresh install and it works, are you sure Voyager is set to use your User Model and not the default one?
Try checking in BREAD -> users -> Model Name
@MrCrayon
I tried using fresh install. Model is correct.
Still, deleting user was not soft deleted.
Do you see this in user list?

If you don't see the third button soft delete is not enabled.
Can you list everything you do after fresh install to enable soft delete?
@MrCrayon
I'm not seeing that one. What did i missed ?
already added on User Model.

The only way I can explain it is if that class is not the one used.
Try adding route below in your route.php
Route::group(['prefix' => 'admin'], function () {
Voyager::routes();
Route::get('/users', function () {
return get_class(auth()->user());
});
});
Then go to /admin/users you should see which class you are using
Nevermind what's written above is going to give you AppUser.
The problem is VoyagerBaseController uses what's in database data_types.model_name and that's, by default, set as TCGVoyagerModelsUser, so unless you changed it that's the model used for users as BREAD.
BTW
Try checking in BREAD -> users -> Model Name
That would have already solved your problem yesterday :wink:
@MrCrayon
Thank You! :)
You are welcome!
Please close the issue if it has been solved.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
Nevermind what's written above is going to give you AppUser.
The problem is VoyagerBaseController uses what's in database data_types.model_name and that's, by default, set as TCGVoyagerModelsUser, so unless you changed it that's the model used for users as BREAD.
BTW
That would have already solved your problem yesterday :wink: