通过Ajax Request Laravel导入模型-无需命名模型

时间:2019-01-29 17:02:43

标签: php laravel eloquent

我正在尝试通过Ajax请求导入模型而不给模型命名。

public function dataTypeRender(Request $request)
{
    $input = request()->all();
    $model = $request->input('model'); //this is the model name
    $cols = $request->input('cols');

    $modelTest = $model::all(); //not working
    dd($modelTest);
}

有没有办法做到这一点?我正在尝试对模型数据进行处理。

2 个答案:

答案 0 :(得分:0)

我认为如果没有名称空间,它会更难一点,因为您的模型可以是任何模型,但是我认为这可以为您提供帮助。

public function example(Request $request){
        $data = $request->all(); //get All data request
        $namespace = 'App\\'; //set namespace
        $modelWithNameSpace =  $namespace.$data['model']; //concat namespace and model name
        $model = str_replace("'", "", $modelWithNameSpace); //remove quotes (idk if it's the best approach)
        return $model::all(); //return the modell with all 

    }

答案 1 :(得分:0)

这似乎很好用。

typedef pid_t (*pidResolver)(pid_t pid);

pidResolver resolver = dlsym(RTLD_NEXT, "responsibility_get_pid_responsible_for_pid");

pid_t trueParentPid = resolver(pid);