问题
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