如何在laravel 4.2中获取softdeleted数据的id

时间:2015-08-31 10:43:19

标签: laravel laravel-4 laravel-5 laravel-5.1 soft-delete

通过ajax发送ID

 <script language="javascript">
    var xmlHttp;
    function Rtask(id) {
        xmlHttp=GetXmlHttpObject();
        if(xmlHttp==null) {
            alert("browser do not support ajax");
            return;
        }

        var url='releaseleader/'+id;
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("POST",url,true);
        xmlHttp.send(null);
        return false;
    }


    function GetXmlHttpObject()
    {
        var objXMLHttp=null;
        if(window.XMLHttpRequest)
        {
            objXMLHttp=new XMLHttpRequest();
        }
        else if(window.ActiveXObject)
        {
            objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return objXMLHttp;
    }
</script>

基于路由&GT;

       Route::Post('releaseleader/{id}','TeamController@releaseleader');

模型 - &GT;

 use Illuminate\Database\Eloquent\SoftDeletingTrait;

 class Tasktime extends Eloquent

 {
public $table='tasktime';
use SoftDeletingTrait;

protected $softDelete = true;

protected $dates = ['deleted_at'];     }

控制器

public function releaseleader($id)
{

    $leader=Tasktime::find($id);
    $leader->delete();


        return Redirect::to('managertask/'.$id);
}

例如在softdelete之后,它不会被重定向到带有id的页面,例如managertask / 17

但在软交换之前,它正在重定向到id为17的页面

请帮帮我

1 个答案:

答案 0 :(得分:0)

Eloquent会自动忽略软删除的行。你可以通过链接withTrashed()方法告诉它不要做。在你的情况下:

$leader = Tasktime::withTrashed()->find($id);