2015-11-03 147 views
1

基本上我設法讓我的軟刪除工作在我的用戶表上,問題是現在我的其他頁面無法工作,我相信我需要使用withTrashed對查詢進行一些更改網頁?例如如下所示的控制器,如何添加已被軟刪除的用戶列,有人可以指導我並幫助我嗎?使用Trash查詢,軟刪除laravel

Controller.php這樣

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 
use App\Http\Controllers\Controller; 
use App\Zone; 
use App\Parameter; 

class DashboardController extends Controller 
{ 
    public function index() { 
     $zones = Zone::all(); 
     $parameters = Parameter::all(); 

     return view('dashboard', compact('zones', 'parameters')); 
    } 
} 
+0

看到這,https://stackoverflow.com/a/45669204/1838205 –

回答

3

您可以再補充->withTrashed()到您的查詢,並使用get代替all。像這樣:

$zones = Zone::all(); //Excludes soft deleted 

$allparameters = Parameter::withTrashed()->get(); //Includes soft deleted 

$allusers = User::withTrashed()->get(); 

此外,onlyTrashed()會做什麼它表明:

$trashedusers = User::onlyTrashed()->get(); //Only soft deleted users