web tech Flashcards

1
Q

What are views ?

A
  • in laravel, views are php files that contain html and php code and are used to render a web applications user interface
  • it is a method in laravel, that separate the controller logic and domain logic from the presentation logic
  • views are located in resource/views folder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to work with views

A
  1. create view file, example, contact.php in resources/views directory

contact.php

<html>
<body>
<h1>Name of the Contact is : </h1>
</body>
</html>

  1. create route in web.php
    web.php

Route::get(‘/contact’, function(){
return view(‘Contact’,[‘name’=>’John’]);
});

In the above code, view() method contains two arguments. The first argument is the name of the file that contains the view, and the second argument is the array passed to the given file. In array, we are passing the name variable to the Contact.php file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

pass data to view using controller

A
  1. create controller

In this example, we use the view() method in the Controller class.

Step 1: First, I need to create a controller. Suppose I have created the controller named ‘PostController’, and then add the code given below in a PostController.php file.

public function display(){
return view(‘about’);
}

Step 2: Now, we create the about.php file in which we add the html code.

<html>
<body>
<h1>About Us</h1>
</body>
</html>

Step 3: Last step is to add the route in web.php file.
Route::get(‘/post’,’PostController@display’);

Step 4: Enter the URL http://localhost/laravelproject/public/post to the web browser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how nesting views work

A
  • Views can also be nested within the sub-directory resources/views directory.

Let’s understand the nested views through an example.

Suppose we want to know the admin details. The view of the admin details is available at the resources/views/admin/details.blade.php directory.

Step 1: First, we create details.blade.php file in the admin folder, and the code of the details.blade.php file is given below:

<html>
<body>
<h1>Admin Details</h1>
</body>
</html>

Step 2: Now, we need to add the display() function in PostController.php file which is returning the view of the ‘admin.details’.

public function display(){
return view(‘admin.details’);
}

Step 3: Lastly, we will add the route in a web.php file.

Route::get(‘/details’, ‘PostController@display’);

Step 4: To see the output, enter the url ‘http://localhost/laravelproject/public/details’ to the web browser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How passing data to views work?

A
  • different ways
  • we can directly pass data through routes or controller

Some ways
- using view()
- using with()
- using compact()
- using controller class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to pass data using view()

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how to pass data using with() method

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how to pass data using compact()

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to pass data using controller class

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to pass data to all routes

A

https://youtu.be/XWB3z5ekIN8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly