/hello page returns <h1> Route::get('/hello', function () {
return '<h1>Hello World</h1>';
});resources/views/pages/about.blade.php Route::get('/hello', function () {
return view('pages/about');
});
pages/about is the same as pages.aboutRoute::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;
});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';
}
}@yield is mainly used to define a section in a layout.
Content of resources/views/layouts/app.blade.php file<body>
@yield('content')
</body>
Content of about page that extends the above layout file@extends('layouts.app')
@section('content')
// "about us" page content goes here
@endsectionpublic function about() {
$param1 = 'this is a parameter of about us page';
return view('pages/about', compact('param1'));
}
Content of about blade (the page receives and uses the passed parameter)@section('cntnt')
<h3>abt us {{$param1}}</h3>
@endsectionpublic function services() {
$data = [
'title' => 'langs',
'languages' => ['PHP', 'Java', 'Python']
];
return view('pages/services')->with($data);
}
Receive the passed array@extends('layouts.app')
@section('cntnt')
<h3>{{$title}}</h3>
@if(count($languages))
@foreach($languages as $language)
<li>{{$language}}</li>
@endforeach
@endif
@endsectionpublic/css/ folder<link href="{{asset('css/app.css')}}" rel="stylesheet">