视图中仍显示软删除 laravel
Soft delete still being shown in view laravel
出于某种原因,当我尝试对我的数据进行软删除时,它们并没有在我的视图中消失(home.blade.php),但在我的数据库中,deleted_at 列已被记录显示我删除它时的日期。能帮我看看我的代码有没有问题,谢谢
这是我的代码:
home.blade.php
<table class="table table-bordered">
<tr>
<th><strong><big>Name: </big></strong></th>
<th><strong><big>Action </big></strong></th>
</tr>
<td>
<tr>
@foreach($data as $value)
<tr>
<th><a href="{{route('user.show',['id'=>$value->id])}}">{{$value->Name}}</a></th>
<th><form action="{{ url('/home/'.$value->id.'/delete') }}" method="get">
{{ csrf_field() }}
<button type="submit">Delete</button>
</form></th>
</tr>
@endforeach
</tr>
</tr>
</table>
家庭控制器:
public function getData(){
$data['data'] = DB::table('personal_infos')->get()->sortByDesc('created_at');
if(count($data)>0){
return view('home',$data);
}else{
return view('home');
}
public function delete($id){
personal_info::findOrFail($id)->delete();
return back();
}
路线:
Route::get('/home/{id}/delete', 'HomeController@delete');
Route::get('user/show/{id}','HomeController@getInfo')->name("user.show");
Personal_info 型号:
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Eloquent;
class personal_info extends Eloquent
{
use SoftDeletes;
protected $fillable = array('Name');
protected $table = 'personal_infos';
protected $primaryKey = 'id';
protected $dates = ['deleted_at'];
public function user_info1s() {
return $this->hasMany('App\user_info1','user_id');
}
Eloquent 查询将在查询使用软删除的模型时,自动排除 所有软删除模型查询结果。
但是,您使用的不是 Eloquent 查询,而是 原始数据库查询 。因此,您还需要检查查询中 deleted_at 列不为空的位置。
出于某种原因,当我尝试对我的数据进行软删除时,它们并没有在我的视图中消失(home.blade.php),但在我的数据库中,deleted_at 列已被记录显示我删除它时的日期。能帮我看看我的代码有没有问题,谢谢
这是我的代码:
home.blade.php
<table class="table table-bordered">
<tr>
<th><strong><big>Name: </big></strong></th>
<th><strong><big>Action </big></strong></th>
</tr>
<td>
<tr>
@foreach($data as $value)
<tr>
<th><a href="{{route('user.show',['id'=>$value->id])}}">{{$value->Name}}</a></th>
<th><form action="{{ url('/home/'.$value->id.'/delete') }}" method="get">
{{ csrf_field() }}
<button type="submit">Delete</button>
</form></th>
</tr>
@endforeach
</tr>
</tr>
</table>
家庭控制器:
public function getData(){
$data['data'] = DB::table('personal_infos')->get()->sortByDesc('created_at');
if(count($data)>0){
return view('home',$data);
}else{
return view('home');
}
public function delete($id){
personal_info::findOrFail($id)->delete();
return back();
}
路线:
Route::get('/home/{id}/delete', 'HomeController@delete');
Route::get('user/show/{id}','HomeController@getInfo')->name("user.show");
Personal_info 型号:
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Eloquent;
class personal_info extends Eloquent
{
use SoftDeletes;
protected $fillable = array('Name');
protected $table = 'personal_infos';
protected $primaryKey = 'id';
protected $dates = ['deleted_at'];
public function user_info1s() {
return $this->hasMany('App\user_info1','user_id');
}
Eloquent 查询将在查询使用软删除的模型时,自动排除 所有软删除模型查询结果。
但是,您使用的不是 Eloquent 查询,而是 原始数据库查询 。因此,您还需要检查查询中 deleted_at 列不为空的位置。