×
Clear all filters including search bar
Valeri Tandilashvili's Laravel Notes
about
returns view from route. Other routes fire PagesController
appropriate methodsRoute::get('/', 'PagesController@index');
Route::get('/about', function () {
return view('pages.about');
});
Route::get('/services', 'PagesController@services');
Route::get('/contact', 'PagesController@contactUs');
PagesController
methodsclass PagesController extends Controller
{
public function index() {
return view('pages.index');
}
public function about() {
return view('pages/about');
}
public function services() {
return view('pages/services');
}
public function contactUs() {
return 'Under Construction';
}
}
Route::get('/users/{name}', function ($name) {
return 'This is a user ' . $name;
});
Two parameters passed through the request URLRoute::get('/users/{name}/{id}', function ($name, $id) {
return 'This is a user ' . $name .' with an id of '. $id;
});
resources/views/pages/about.blade.php
Route::get('/hello', function () {
return view('pages/about');
});
pages/about
is the same as pages.about
/hello
page returns <h1>
Route::get('/hello', function () {
return '<h1>Hello World</h1>';
});
/hello
page returns text Hello World
Route::get('/hello', function () {
return 'Hello World';
});
config/database.php
Route::get('/', function () {
return view('welcome');
});
get
- type of HTTP request
/
- stands for the homepage
welcome
- view file located at resources/views/welcome.blade.php
The route will return welcome
view file contentroutes/web.php
resources/views
folder.
All laravel views use blade
template engine.
Views files contain the word in its name like welcome.blade.php
app/Http/Controllers
folder with plural form like UsersController.php
in Laravel older versions but with singular form like UserController.php
in new versions of Laravel