Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
视图laravel中仍显示软删除_Laravel_Soft Delete - Fatal编程技术网

视图laravel中仍显示软删除

视图laravel中仍显示软删除,laravel,soft-delete,Laravel,Soft Delete,由于某种原因,当我尝试对数据进行软删除时,它们并没有在我的视图(home.blade.php)中消失,而是在我的数据库中,记录了deleted_at列,显示了我删除数据的日期。你能帮我检查一下代码吗?有什么问题吗?谢谢 这是我的密码: home.blade.php <table class="table table-bordered"> <tr> <th><strong><big>Name: </bi

由于某种原因,当我尝试对数据进行软删除时,它们并没有在我的视图(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>
路线:

Route::get('/home/{id}/delete', 'HomeController@delete');
Route::get('user/show/{id}','HomeController@getInfo')->name("user.show");
个人信息模型:

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');
    }

雄辩查询使用软删除的模型时,将自动从所有查询结果中排除软删除的模型


但是,您使用的不是雄辩的查询,而是原始数据库查询。因此,您还需要检查在查询中删除的_at列在何处不为空。

您的主视图控制器方法是什么样子的?@kerrin Hi,tks用于答复我在问题中为视图添加了控制器Hi tks用于答复,我尝试了您的建议,但我不知道如何真正实现它,在过去,当我做一些不为空的事情时,我会做一些类似的事情!=空或只是放不空,但对于拉雷维尔,我仍然不太确定,我做了类似的事情,你能告诉我正确的方法吗?“$data['data']=DB::table('personal_infos')->where('deleted_at','notnull')->get()->sortByDesc('created_at');”嗨,对不起,我发现了我的错误,我想把NULL改为notnull,哈哈哈。非常感谢您帮助meExcellent,很高兴您得到了它!
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');
    }