Home > Backend Development > PHP Tutorial > How to write this laravel route?

How to write this laravel route?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-29 16:09:39
Original
1122 people have browsed it

这个路由要怎么写
/{model}/lists 转发到{$model}Controller控制器的lists方法
如 /shop/lists => shopController控制器 lists方法,
/user/lists => userController控制器 lists方法,
不能手动一个个写 我有好多model啊

回复内容:

根据规范,应该使用 ShopController 作为类名。

以下代码适用于 Laravel 5.0 及以上:
<code class="language-text">Route::get('{model}/lists', function ($model) {
  $className = 'App\Http\Controllers\\'.ucfirst($model).'Controller';
  $obj = new $className;
  return $obj->lists();
});
</code>
Copy after login
一个一个写最好;
laravelbase.com/collect 最简单的办法,真的是一个一个写。
<code class="language-php"><span class="x">Route::group(['prefix' => 'shop'], function() {</span>
<span class="x">    Route::get('list', 'ShopController@list');</span>
<span class="x">})</span>
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Python two lists added
From 1970-01-01 08:00:00
0
0
0
java - bean collection split into multiple lists
From 1970-01-01 08:00:00
0
0
0
Nested lists in different styles
From 1970-01-01 08:00:00
0
0
0
python - Merge multiple lists into a dictionary
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template