Why the deleted data still appear in the interface?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 09:54:19

问题


Look here :

When I click button delete, data deleted still appear in the interface.

I look at the table in the database, the data is erased.

Data can be lost if I run this: php artisan cache:clear on git bash.

How without running the command, data can be erased?

UPDATE

My controller is like this :

public function deleteAccount(Request $request)
{
    $id_account = $request->input('id_account');
    try{
        if($this->user_service->deleteAccount($id_account)) {
            $status='success';
        }else {
            $status = 'failed';
        }
        return redirect('member/profile/setting/account')->with('status',$status);
    }catch (\Exception $exception){
        return $this->respondInternalError();
    }
}

My service is like this :

public function deleteAccount($id_account)
{
    return $this->user_bank_repository->delete($id_account);
}

My repository is like this :

<?php
namespace App\Repositories;
use App\Models\UsersBank;
use Illuminate\Contracts\Container\Container;
use Rinvex\Repository\Repositories\EloquentRepository;
class UserBankRepository extends EloquentRepository
{
    public function __construct(Container $container)
    {

        $this->setContainer($container)
             ->setModel(UsersBank::class)
             ->setRepositoryId('rinvex.repository.uniqueid');
    }
    public function delete($id)
    {
        $data = self::find($id)->delete();
        return $data;
    } 
}

回答1:


I see you are also using the rinvex repository. I don't see your code about fetch data. I assume you are fetching data from the repository cache. In your repository, your delete function.

public function delete($id){
    return $this->delete($id);
}

this should clear the repository cache. if you would like clear the cache of the repository manually, try the following in your repository method.

$this->forgetCache();

or

$this->getContainer('events')->fire($this->getRepositoryId() . '.entity.updated', [$this, $modelInstance]);

actually forgetCache() method shall do, I'm using it in my repository after I made mass update to my table.



来源:https://stackoverflow.com/questions/41788737/why-the-deleted-data-still-appear-in-the-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!