0
我有一個有兒童記錄的記錄。現在,當我嘗試刪除該記錄時,應該說「您不能刪除此記錄;因爲它有一個子記錄」。如何做到這一點是laravel 5?例如:如何在刪除laravel 5中的父記錄時不刪除子記錄?
例如: 設備記錄有一個部門欄,當我嘗試刪除這個設備記錄時,它應該給出一條消息:「這個記錄有一個部門,你不能刪除它」。
這是我的遷移腳本:
public function up()
{
Schema::create('equipment', function(Blueprint $table){
$table->string('id', 32)->unique()->index();
$table->string('equipment_no',32);
$table->string('organization_id',32)->index();
$table->foreign('organization_id')->references('id')->on('organization')->onDelete('cascade')->onUpdate('cascade');
$table->string('customer_id',32)->index();
$table->foreign('customer_id')->references('id')->on('customer')->onDelete('cascade')->onUpdate('cascade');
$table->string('equipment_type',32);
$table->string('equipment_category_id',32)->index();
$table->foreign('equipment_category_id')->references('id')->on('equipment_category')->onDelete('cascade')->onUpdate('cascade');
$table->string('equipment_model_id',32)->index();
$table->foreign('equipment_model_id')->references('id')->on('equipment_model')->onDelete('cascade')->onUpdate('cascade');
$table->string('equipment_fabricat_id',32)->index();
$table->foreign('equipment_fabricat_id')->references('id')->on('equipment_fabricat')->onDelete('cascade')->onUpdate('cascade');
$table->string('department_id',32)->index();
$table->foreign('department_id')->references('id')->on('department')->onDelete('cascade')->onUpdate('cascade');
$table->text('location');
$table->string('inspection_interval',45);
$table->foreign('added_by')->references('id')->on('user')->onDelete('cascade')->onUpdate('cascade');
$table->SoftDeletes();
$table->timestamps();
});
}
和我滅控制器頁面功能:
public function destroy($id)
{
$equipment = Equipment::findOrFail($id);
$equipment->delete();
return Redirect::route($this->route)->with($this->success, trans($this->deletemsg));
}
誰能幫我一下吧?
請顯示一些代碼 - 您有什麼,您錯過了什麼。 –