This article describes the Laravel routing setting and sub-routing setting method with examples. Share it with everyone for your reference, the details are as follows:
Normal routing settings
1. Routing (routes.php) code:
Route::get('min','MinController@index');
min: is the route name, which is entered in the URL, such as 127.0.0.1/min The min here is the corresponding min
above
MinController is the file name (class name)
@index is the method name
2. Controller
namespace App\Http\Controllers; use App\Http\Controllers\Controller; class MinController extends Controller{ public function index(){ $name = 'Specs1'; return view('index')->with('name',$name); } }
Subroute
1. Routing:
Route::group(['namespace' => 'Min'], function () { Route::get('min/{index}','MinController@index'); //这里的{index}类似于正则,即url可以随意输:127.0.0.1/min/$index 就像变量一样,输什么都可以。但是后面的@index是真正的方法 });
Controller:
namespace App\Http\Controllers\Min;//Min是控制器的文件夹路径 use App\Http\Controllers\Controller; class MinController extends Controller{ public function index(){ $name = 'Specs1'; return view('min.index')->with('name',$name);//这里的min.index等价于min/index 是min视图文件夹下面的index.blade.php文件 } }
Structure diagram:
Readers who are interested in more information about Laravel can check out the special topics on this site: "Introduction and Advanced Tutorial on Laravel Framework", "Summary of PHP Excellent Development Framework", "Basic Tutorial on Getting Started with Smarty Templates", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope this article will be helpful to everyone’s PHP program design based on the Laravel framework.