Laravel Basic of Route and View
Consider any URL send request form the browser and go to server and that server use Laravel as a backend and perform the following steps:
- Route File looks at the request: Request first of all goes to route file and it looks the request and decide what to do next
- Get or process any data needed: Then it processes some data and save it to database or retrieve data or something else
- Compile a view to return: At Last we could inject it into view which is Just an HTML Template, compile that and return it to the user so they can see in the browser
Let’s do some practical work
- Go to Routes Folder and there is different file we will work on web. Php file
- There is one route setup and we do this using the Route class and there is a method called get with 2 parameters first is route (‘/’, ‘/contact’) and next is callback function that return a view.
- These views are placed in resources folder
- Click on the view folder and there is file with name welcome.blade.php.
- Here welcome is the name of view
- blade is template engine
- php is extension
This page is just HTML with some blade syntax and dynamic content
Example
Route::get(‘/’, function(){
return view(‘welcome’);
})