2016-11-15 31 views
0

下面的代碼是控制器的代碼。這個代碼的工作原理,但值只從頁面中刪除。從表中,值不會被刪除。我可以做什麼從頁面和表中刪除值?如何從表中刪除值?

public function deleteconfirms($id) 
    {  
     $employee = CreateEmployee::find($id); 

     $employee->destroy($id);   

     Session::flash('flash_notification', array('level' => 'success', 'message' => 'employee deleted successfully')); 

     return Redirect::action('Admin\[email protected]'); 

    } 
+0

你使用softdelete嗎? –

回答

0

看看下面的代碼。 通常,不要將您的模型命名爲CreateEmployee,只將其稱爲Employee。這會造成混亂。

public function deleteconfirms($id) 
{  
    $employee = CreateEmployee::destroy($id); 

    Session::flash('flash_notification', array('level' => 'success', 'message' => 'employee deleted successfully')); 

    return redirect()->action('Admin\[email protected]'); 

} 
0

當模型被軟刪除時,它們實際上並未從數據庫中刪除。而是在模型上設置deleted_at屬性並將其插入到數據庫中。如果模型具有非空的deleted_at值,則該模型已被軟刪除。

檢查您是否在CreateEmployee模型中使用以下代碼。

use Illuminate\Database\Eloquent\SoftDeletes; 
class CreateEmployee extends Model 
{ 
    use SoftDeletes; 

    /** 
    * The attributes that should be mutated to dates. 
    * 
    * @var array 
    */ 
    protected $dates = ['deleted_at']; 
} 

如果您不想軟刪除,請將其刪除並使用直接刪除。