Route::get('/', 'WelcomeController@index');
@ is a qualifier, preceded by a controller, followed by an action, indicating that the index method in the controller Welcomecontroller is executed when the user requests the URL/
app/http/controllers/welcomecontroller.php
public function index(){return view('welcome');}
Currently returns a view by default, the name of the view is welcome, and the Welcome.blade.php,blade is actually a laravel view template.
public function index(){// return view('welcome');return 'hello, laravel';}
在浏览器中测试,得到一个简单的反馈。
- We create a new route, which is added in routes.php:
Route::get('/contact', 'WelcomeController@contact');
You can create a new route, but now we are using the default controller directly, adding it in welcomecontroller.php:
public function contact() { return 'Contact Me';}
在浏览器终测试新增加的路由。
We can return a simple string, or we can return a JSON or HTML file, and all of the view files are stored in resource->views.
For example return view('welcome')
, we do not need to consider the path or add the. blade.php extension, and the framework automatically completes for us. If you need subdirectories in the views directory, such as the Views/forum subdirectory, you only need return view('forum/xxx')
to, or follow the simple and clear way: return view('forum.xxx')
.??
We return to a page
public function contact() { return view('pages.contact');}
- Create the pages directory under the Views directory and create the contact.blade.php
DocumentContact
The above describes the Laravel 5 Basic (ii)-routing, Controller and view introduction, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.