Home > Article > Backend Development > Introduction to Laravel 5 framework learning routes, controllers and views, laravel framework_PHP tutorial
View app/Http/routes.php
Copy code The code is as follows:
Route::get('/', 'WelcomeController@index');
@ is a delimiter, preceded by the controller and followed by the action, which means that when the user requests url /, the index method in the controller WelcomeController is executed
Copy code The code is as follows:
app/http/controllers/welcomecontroller.php
public function index()
{
return view('welcome');
}
Currently, a view is returned by default. The name of the view is welcome, which is actually welcome.blade.php. Blade is the view template of laravel.
You can view `resources/views/welcome.blade.php
Modify welcomecontroller.php
Copy code The code is as follows:
public function index()
{
// return view('welcome');
return 'hello, laravel';
}
Test in your browser and get a simple feedback.
We create a new route and add:
in routes.phpCopy code The code is as follows:
Route::get('/contact', 'WelcomeController@contact');
You can create a new route, but for now we still use the default controller directly and add:
to WelcomeController.phpCopy code The code is as follows:
public function contact() {
Return 'Contact Me';
}
Test the newly added route in the browser.
We can return a simple string, or a json or html file. All view files are stored in resource->views.
For example: return view('welcome') , we don't need to consider the path, and don't add the .blade.php extension, the framework does it for us automatically. If you need a subdirectory in the views directory, such as the views/forum subdirectory, you only need to return view('forum/xxx'), or the simple and clear way is: return view('forum.xxx'). 😄
We return to a page
Copy code The code is as follows:
public function contact() {
Return view('pages.contact');
}
Create the pages directory under the views directory, and then create contact.blade.php
Copy code The code is as follows:
The above is the entire content of this article. I hope it will be helpful to everyone learning Laravel5.