Laravel Classroom image

CiliSp
 
To post your Question Join Classroom
 
Lesson Topics's No:-  |1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9|Last
Lessons:-Handling Input

Handling Input
Now that we know how to create forms, we need to learn how to handle the input that has been
sent by them. As always, Laravel has provided an ultra clean way of dealing with your input
data. No need to interact with PHP arrays such as $_POST, $_GET and $_FILES. Let’s be honest,
those look ugly.
7.1 Request data
Let’s use the Input class to handle this instead.
1 <?php
2
3 $panda = Input::get('panda');
Now we have a Panda! Great.. we have too many already. Due to an unfortunate welsh border
breach, Wales is now infested with red pandas. They are everywhere, I’m using one as a footrest
right now. How did you think Emma managed to snap up that cover shot, they come from China!
Anyway, let’s get back on track. One thing that you need to remember about the get() method
on the Input class is that it doesn’t refer to $_GET data. You will see that get() is simply a nice
and expressive short method name for retrieving all kinds of data. The Input class also responds
to get() with all kinds of request data, including $_POST.
If a piece of request data isn’t set, the Input class will return a null value. If you pass a second
parameter to the get() method and the index doesn’t exist then the method will return the second
parameter instead. This means that you can use it without worrying about any undefined errors
popping up. Very useful!
1 <?php
2
3 $panda = Input::get('panda', 'Muffin');
Now if our panda doesn’t have a name it will be called ‘Muffin’, awwww..
If you would like to retrieve the entire request array, just skip the index. Easy as that.
1 <?php
2
3 $morepandas = Input::get();
By default the get() array won’t includes values from the $_FILES array. However if you use
all() instead of get() it will contain files too.

 
 
 

CiliSp

Skills    Laravel

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)