Views in Laravel

View is a part of MVC known to be model view controller. View is present in Laravel as well as any mvc framework like xend or tech php etc.

What you will do in view is -:

– You put the html part in view that you want to show to the user. As different links, icons etc. everything is present inside the Laravel view. You can check it in “welcome.blade.php” file placed in views which is placed in resources folder which generate the view output of Laravel page.

Now go to how you can make the view or just show how view is created-:

– For this create new file in resources named with “users.blade.php”.

As blade is not part of mvc or neither it’s part of view, this is Templating engine which is provided by Laravel.

Both ways you can do are you can just call it from the routing and as well as how you can call it from the controller.

  1. First check it out from routing.
  2. So, let’s go to the routes file>web.php and make route which respective code modules.

    
     $name]);
    });
    

    And on other side in users.blade.php you should also describe the users there as-:

    < h1> Hello {{$name}} < /h1>

  3. 2) Now look for how to call from controller-:
  4. – Go to console> make a controller just like

    Php artisan make: controller UsersController

    And controller is created inside the app at http> controllers> usersController.php

    – Make a function in userscontroller.php file as-:

    
    

    – Go to “users.blade.php” and write header statement.

    – One more thing you have to do for Userscontroller.php- route for this controller. So, go to web.php, include controller file and define a route for controller as below respectively-:

    
    

    Route for controller is as-:

    
    

    So see the result which will works fine-:

    But how you can pass the data from controller to the view so for this you can put two things-:

  1. You can just put some static data in “usercontroller.php” file.
  2.  Function loadview ()
    {
           Return view {“users”,[‘name’ => “abc”]);
    }
    

    And to see result in browser fetch it in “usersblade.php” as-:

    < h1> Hello {$name} < /h1>

  3. You can pass parameter as route also in web.php as-:
  4. Route::get (“user/ {name}”, [UersController::class,’loadview’]);

    And now in controller just simply put “$name” as a static name as-:

    Function loadview($name)

    {
           Return view (“users”, [‘name’ => $name]);
    }
    

    So in result whatever you will put the name in browser will automatically print as output.

So this is the way that how you can use the view and you can call it from the controller as well as from the view.

Copyright 1999- Ducat Creative, All rights reserved.