我正在为应用创建API。现在app开发人员希望我创建一个固定的基本URL并将ROUTE NAME(将指向控制器功能)作为POST变量传递。例如:
和POST变量如:
{{1}}
但是在laravel中我们可以根据url部分定义路径:
我尝试使用单个控制器并根据SWITCH语句加载其他控制器。但这似乎并不是一种标准做法,因为每次我创建新的API时都需要添加切换条件。中间件也无法动态加载控制器。 laravel有没有办法实现这一目标?我正在使用laravel 5.4
答案 0 :(得分:0)
您可以实施一个middleware来监听$request
路由,该路由从Route()
获取// Generating ROUTE_NAME url...
$url = route($request->route_name);
// Redirect to that route...
return redirect()->route($url);
,然后您就可以使用#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
double squareroot(double number){ //function to find squareroot.
return sqrt(number); //variable for the square of number1
}
int main() { // main function
int number1 = 0; //first number - integer
int number2 = 0; //second number - integer
int number3 = 0; //third number - integer
cout << "\ntype number1"; //asks user to input first number
cin >> number1; //stores user input into variable number1
cout << "\ntype number2"; //asks for second number
cin >> number2; //stores second number into number2
cout << "\ntype number3"; // asks for third number
cin >> number3; //stores third number
cout << squareroot(number1) << "\n"; //outputs number1
cout << squareroot(number2) << "\n"; //ouputs number2
cout << squareroot(number3) << "\n"; //outputs number3
}
帮助函数找到该命名路由的url,然后将请求重定向到该路由。
类似的东西:
win32gui
显然,如果找不到路由等,你需要添加代码来处理,可能会返回一个带有正确错误代码的json响应等。