2016-11-15 36 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']; 
} 

如果您不想软删除,请将其删除并使用直接删除。