您好,我无法删除我的数据,这是为什么?这是我的代码
在 Controller
上 public function displayArchive()
{
$clients = Client::withTrashed();
return view('admin.clients.homeArchive')->with('clients', $clients);
}
其中一个查看
<table class="table table-bordered" id="dynamic_field">
<tr>
<th>Client Code</th>
<th>Client Name</th>
<th>Address</th>
<th>Tel No.</th>
<th>Contact Person</th>
<th>Mobile No.</th>
<th>Email Address</th>
<th>Website</th>
<th>Status</th>
<th>Update</th>
</tr>
@foreach ($clients as $client)
<tr>
<td>{{ $client->client_code }}</td>
<td>{{ $client->client_name }}</td>
<td>{{ $client->address }}</td>
<td>{{ $client->tel_no }}</td>
<td>{{ $client->contact_person }}</td>
<td>{{ $client->mobile_no }}</td>
<td>{{ $client->email_ad }}</td>
<td>{{ $client->website }}</td>
<td><a href="#" class="btn btn-danger">Inactive</a></td>
<td><a href="/admin/clients/{{ $client->id }}/edit" class="fa fa-edit btn btn-primary"></a></td>
</tr>
@endforeach
</table>
在网络上 在这里您可以看到我如何调用我的 Controller 和 View 页面。
Route::get('/admin/clients/homeArchive', 'Admin\ClientsController@displayArchive');
已编辑 这是编辑后的代码,请查看 我的模特
use SoftDeletes;
protected $dates = ['deleted_at'];
// Table Name
protected $table = 'clients';
// Primary Key
public $primaryKey = 'id';
// Timestamps
public $timestamps = true;
最佳答案
你可以尝试使用 ->get()
方法吗?
public function displayArchive()
{
$clients = Client::withTrashed()->get();
return view('admin.clients.homeArchive')->with('clients', $clients);
}
注意:它不会取消删除任何数据。它只获取已删除行的数据。
如果要恢复已删除的数据,必须使用->restore()
方法。
对于所有恢复的所有数据;
链接:
<a href="{{ route('admin.client.restore_all') }}" class="btn btn-danger">Inactive</a>
路线:
Route::get('/admin/clients/restore-all', 'Admin\ClientsController@restoreAll')->name('admin.client.restore_all');
Controller 操作:
public function restoreAll(){
Client::withTrashed()->restore();
}
逐行恢复数据;
链接:
<a href="{{ route('admin.client.restore', $client->id) }}" class="btn btn-danger">Inactive</a>
路线:
Route::get('/admin/clients/restore/{client}', 'Admin\ClientsController@restore')->name('admin.client.restore');
Controller 操作:
public function restore(Client $client){
$client->restore();
}
$client->id
是客户端集合,我想你想在列出的 foreach 行中处于非事件状态,对吗?
关于php - Laravel - 无法使用软删除取消删除和显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53560333/