3. 3
Passing data is process of how we can take variable data,
and pass it to our views to be rendered in the Browser.
4. 4
Laravel provides
different ways to pass
data to a view. We can
pass data directly from
routes or through the
controller
• Using view()
• Using with()
• Using compact()
• Using Controller
Class
5. We can directly pass the data in the ‘view()’
helper function by using the second parameter
in the function which takes an array as key and
value pair
In view(), the first parameter is the name of the
view and the second parameter is where we
have specified one key and multiple values of
the data.5
6. The ‘with()’ is a method to pass individual form of data
and is used with the ‘view’ helper function
As you can see in the above code, we have to specify an
arrow ‘->’ and then use the ‘with()’ method with ‘view()’
helper function. And we can specify one or more ‘with()’
depending on the requirement and use case.
6
7. The ‘compact()’ is a PHP function that can be used for creating an
array with variable and there value. Here the name on the
variable is the key and the variable content is the value
In view(), the first parameter is the name of the view and second
is where we have to specify the ‘compact()’ function.
7
8. Passing data using controller class is easy and is the right way
In above function, we saw that we make use of the view() function.
It’s first argument is a string which specifies which view file to
load. The second argument to view() is an array which holds
dynamic data that we can pass to the view file.
8
9. HTTP works as a request-response protocol between a
client and server.
Example: A client (browser) sends an HTTP request to
the server; then the server returns a response to the
client. The response contains status information about
the request and may also contain the requested content.
So, request is what the client asks for the server to fulfill
9
11. To obtain an instance of the current HTTP
request via dependency injection, you should
type-hint the IlluminateHttpRequest class on
your controller method.
11
12. Andi Nurkholis, S.Kom., M.Kom.
September 28, 2020October 19, 2020
Study Program of Information Systems
Faculty of Engineering and Computer Science
SY. 2020-2021