Php Laravel路由条件基于哪条路径,如何获得正确的路径

Php Laravel路由条件基于哪条路径,如何获得正确的路径,php,ajax,laravel,datatables,Php,Ajax,Laravel,Datatables,我的路线: 不同视图的路径 路线::获取“/参与者”,'DatatablesController@getIndex“->命名“参与者”; 路由::获取“/完成”,'DatatablesController@getIndex'->名称“已完成”; 路由::获取“/失败”,'DatatablesController@getIndex'->名称“失败”; //将数据获取到视图的路由 路线::获取“参与者”DatatablesController@getData'->命名为'get.survey_req

我的路线:

不同视图的路径

路线::获取“/参与者”,'DatatablesController@getIndex“->命名“参与者”; 路由::获取“/完成”,'DatatablesController@getIndex'->名称“已完成”; 路由::获取“/失败”,'DatatablesController@getIndex'->名称“失败”; //将数据获取到视图的路由 路线::获取“参与者”DatatablesController@getData'->命名为'get.survey_requests'; 控制器:

public function getData()
{
    $request = Request::path();
    error_log($request);
    // $request returns participant_dt currently.
    // I want it to return based on which view I'm on.

    if ($request == 'participants') {
        //return query
    } elseif ($request == 'complete') {
        //return complete
    } else {
        //return failed
    }
}
public function getCompleted() {
    $this->getData('completed');
}

public function getFailed() {
   $this->getData('failed');
}

protected function getData($status_type = 'participants')
{
    if ($status_type == 'participants') {
        //return query
    } elseif ($status_type == 'complete') {
        //return complete
    } else {
        //return failed
    }
}

有没有办法根据我的路线命名?e、 g.如果选择了route/complete,则路线参与者将被命名为complete?

,因为您的视图位于不同的路线上,您可以使用前面的URL来确定请求来自哪个视图

公共函数getData { $request=url->previous;//获取上一个url $request=parse_url$request['path'];//删除域名 $request=ltrim$request,'/';//删除第一个斜杠 错误日志$请求; dd$request;//返回视图所在的路由,例如:参与者 如果$request==“参与者”{ //返回查询 }elseif$request==“完成”{ //返回完成 }否则{ //返回失败 } }
希望这对您有所帮助

因为您的视图位于不同的路径上,您可以使用前面的URL来确定请求来自哪个视图

公共函数getData { $request=url->previous;//获取上一个url $request=parse_url$request['path'];//删除域名 $request=ltrim$request,'/';//删除第一个斜杠 错误日志$请求; dd$request;//返回视图所在的路由,例如:参与者 如果$request==“参与者”{ //返回查询 }elseif$request==“完成”{ //返回完成 }否则{ //返回失败 } }
希望这对您有所帮助。理想情况下,您的路由应该转到控制器中的不同方法。例如:

Route::get('/completed', 'DatatablesController@getCompleted')->name('completed');
Route::get('/failed', 'DatatablesController@getFailed')->name('failed');
然后在控制器中:

public function getData()
{
    $request = Request::path();
    error_log($request);
    // $request returns participant_dt currently.
    // I want it to return based on which view I'm on.

    if ($request == 'participants') {
        //return query
    } elseif ($request == 'complete') {
        //return complete
    } else {
        //return failed
    }
}
public function getCompleted() {
    $this->getData('completed');
}

public function getFailed() {
   $this->getData('failed');
}

protected function getData($status_type = 'participants')
{
    if ($status_type == 'participants') {
        //return query
    } elseif ($status_type == 'complete') {
        //return complete
    } else {
        //return failed
    }
}

希望这会有所帮助。

理想情况下,您的路由应该转到控制器中的不同方法。例如:

Route::get('/completed', 'DatatablesController@getCompleted')->name('completed');
Route::get('/failed', 'DatatablesController@getFailed')->name('failed');
然后在控制器中:

public function getData()
{
    $request = Request::path();
    error_log($request);
    // $request returns participant_dt currently.
    // I want it to return based on which view I'm on.

    if ($request == 'participants') {
        //return query
    } elseif ($request == 'complete') {
        //return complete
    } else {
        //return failed
    }
}
public function getCompleted() {
    $this->getData('completed');
}

public function getFailed() {
   $this->getData('failed');
}

protected function getData($status_type = 'participants')
{
    if ($status_type == 'participants') {
        //return query
    } elseif ($status_type == 'complete') {
        //return complete
    } else {
        //return failed
    }
}

希望这能有所帮助。

您所处的视图是什么意思?你根本看不到!!视图上的标记与通过直接URL(如localhost:8000/participants)访问没有任何区别,您无法分辨差异您所处的视图是什么意思?你根本看不到!!视图上的标记与通过localhost:8000/participants\u dt等直接URL访问没有任何区别,您无法判断区别。我尝试了此操作,但它从未更改$status\u类型,仅在status\u类型为participants时显示查询。我尝试了此操作,但从未更改$status\u类型,仅当status_type为participants时才显示查询。