Eun*_*nJi 3 laravel laravel-5.1
基本上,我设法在用户表上进行软删除。问题是现在我的其他页面无法正常工作,我相信我需要使用withTrashed对页面查询进行一些更改吗?例如,如下所示的控制器,如何添加已被软删除的“用户”列,有人可以指导我并帮助我吗?
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'));
}
}
Run Code Online (Sandbox Code Playgroud)
您可以添加->withTrashed()
到查询中,然后使用get
代替all
。像这样:
$zones = Zone::all(); //Excludes soft deleted
$allparameters = Parameter::withTrashed()->get(); //Includes soft deleted
$allusers = User::withTrashed()->get();
Run Code Online (Sandbox Code Playgroud)
此外,onlyTrashed()
将按照建议进行操作:
$trashedusers = User::onlyTrashed()->get(); //Only soft deleted users
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5246 次 |
最近记录: |