我正在使用Laravel 5.8,并创建了一个中间件:
constructor(props) {
super(props);
this.graphRef = React.createRef();
this.state = {
nodes: [{ id: 1, title: 'Valley', type: 'ford' }, { id: 2, title: 'Valley 2', type: 'ford' }],
links: [{ source: 1, target: 2 }],
}; //testing data
this.linkGroup = null;
this.iconGroup = null;
this.nodeGroup = null;
this.textGroup = null;
this.simulation = null;
}
componentDidMount() {
const domNode = this.graphRef.current;
const { links } = this.state;
const { width, height } = domNode.getBoundingClientRect();
const svg = d3.select(domNode);
this.linkGroup = svg.append('g').attr('class', 'links');
this.iconGroup = svg.append('g').attr('class', 'icons');
this.nodeGroup = svg.append('g').attr('class', 'nodes');
this.textGroup = svg.append('g').attr('class', 'texts');
this.simulation = d3.forceSimulation()
.force('charge', d3.forceManyBody().strength(5))
.force('link', d3.forceLink(links, link => link.id))
.force('centerX', d3.forceX(width / 2))
.force('centerY', d3.forceY(height / 2))
.force('collision', d3.forceCollide().radius(25).strength(1));
this.triggerSimulation();
}
在kernel.php中注册为
class ResourceMiddleware {
public function handle($request, Closure $next, $resource){}
}
创建了这样的路线:
protected $routeMiddleware = [
'resource' => 'App\Http\Middleware\ResourceMiddleware',
];
当我访问GET / resource时出现错误:未定义变量 Laravel以某种方式希望ResourceMiddleware类中的参数名称应为$ test。如果我将参数名称更改为$ test,则不会发生错误,并且$ test的值将为“ test”。我在做什么错了?
我尝试了不同的语法,例如'middleware'=> ['resource:test']或-> middleware('resource:test')。没有一个。
有一种语法可以定义参数名称和值?该文档指出语法为middleware:value。为什么参数名称应等于值?
最诚挚的问候。