-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests.html
213 lines (139 loc) · 6.63 KB
/
requests.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Requests & Input</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/ubuntu-font.css">
<script src="vendor/modernizr-2.6.2.min.js"></script>
<script type="text/javascript" src="vendor/google-code-prettify/prettify.js"></script>
</head><body><section class="docs-content"><div class="container">
<article class="docs-body"><h1>Requests & Input</h1>
<p><a name="basic-input"></a></p>
<h2>Basic Input</h2>
<p>You may access all user input with a few simple methods. You do not need to worry about the HTTP verb used for the request, as input is accessed in the same way for all verbs.</p>
<p><strong>Retrieving An Input Value</strong></p>
<pre class="prettyprint"><code>$name = Input::get('name');
</code></pre>
<p><strong>Retrieving A Default Value If The Input Value Is Absent</strong></p>
<pre class="prettyprint"><code>$name = Input::get('name', 'Sally');
</code></pre>
<p><strong>Determining If An Input Value Is Present</strong></p>
<pre class="prettyprint"><code>if (Input::has('name'))
{
//
}
</code></pre>
<p><strong>Getting All Input For The Request</strong></p>
<pre class="prettyprint"><code>$input = Input::all();
</code></pre>
<p><strong>Getting Only Some Of The Request Input</strong></p>
<pre class="prettyprint"><code>$input = Input::only('username', 'password');
$input = Input::except('credit_card');
</code></pre>
<p>Some JavaScript libraries such as Backbone may send input to the application as JSON. You may access this data via <code>Input::get</code> like normal.</p>
<p><a name="cookies"></a></p>
<h2>Cookies</h2>
<p>All cookies created by the Laravel framework are encrypted and signed with an authentication code, meaning they will be considered invalid if they have been changed by the client.</p>
<p><strong>Retrieving A Cookie Value</strong></p>
<pre class="prettyprint"><code>$value = Cookie::get('name');
</code></pre>
<p><strong>Attaching A New Cookie To A Response</strong></p>
<pre class="prettyprint"><code>$response = Response::make('Hello World');
$response->withCookie(Cookie::make('name', 'value', $minutes));
</code></pre>
<p><strong>Creating A Cookie That Lasts Forever</strong></p>
<pre class="prettyprint"><code>$cookie = Cookie::forever('name', 'value');
</code></pre>
<p><a name="old-input"></a></p>
<h2>Old Input</h2>
<p>You may need to keep input from one request until the next request. For example, you may need to re-populate a form after checking it for validation errors.</p>
<p><strong>Flashing Input To The Session</strong></p>
<pre class="prettyprint"><code>Input::flash();
</code></pre>
<p><strong>Flashing Only Some Input To The Session</strong></p>
<pre class="prettyprint"><code>Input::flashOnly('username', 'email');
Input::flashExcept('password');
</code></pre>
<p>Since you often will want to flash input in association with a redirect to the previous page, you may easily chain input flashing onto a redirect.</p>
<pre class="prettyprint"><code>return Redirect::to('form')->withInput();
return Redirect::to('form')->withInput(Input::except('password'));
</code></pre>
<blockquote>
<p><strong>Note:</strong> You may flash other data across requests using the <a href="/docs/session">Session</a> class.</p>
</blockquote>
<p><strong>Retrieving Old Data</strong></p>
<pre class="prettyprint"><code>Input::old('username');
</code></pre>
<p><a name="files"></a></p>
<h2>Files</h2>
<p><strong>Retrieving An Uploaded File</strong></p>
<pre class="prettyprint"><code>$file = Input::file('photo');
</code></pre>
<p><strong>Determining If A File Was Uploaded</strong></p>
<pre class="prettyprint"><code>if (Input::hasFile('photo'))
{
//
}
</code></pre>
<p>The object returned by the <code>file</code> method is an instance of the <code>Symfony\Component\HttpFoundation\File\UploadedFile</code> class, which extends the PHP <code>SplFileInfo</code> class and provides a variety of methods for interacting with the file.</p>
<p><strong>Moving An Uploaded File</strong></p>
<pre class="prettyprint"><code>Input::file('photo')->move($destinationPath);
Input::file('photo')->move($destinationPath, $fileName);
</code></pre>
<p><strong>Retrieving The Path To An Uploaded File</strong></p>
<pre class="prettyprint"><code>$path = Input::file('photo')->getRealPath();
</code></pre>
<p><strong>Retrieving The Size Of An Uploaded File</strong></p>
<pre class="prettyprint"><code>$size = Input::file('photo')->getSize();
</code></pre>
<p><strong>Retrieving The MIME Type Of An Uploaded File</strong></p>
<pre class="prettyprint"><code>$mime = Input::file('photo')->getMimeType();
</code></pre>
<p><a name="request-information"></a></p>
<h2>Request Information</h2>
<p>The <code>Request</code> class provides many methods for examining the HTTP request for your application and extends the <code>Symfony\Component\HttpFoundation\Request</code> class. Here are some of the highlights.</p>
<p><strong>Retrieving The Request URI</strong></p>
<pre class="prettyprint"><code>$uri = Request::path();
</code></pre>
<p><strong>Determining If The Request Path Matches A Pattern</strong></p>
<pre class="prettyprint"><code>if (Request::is('admin/*'))
{
//
}
</code></pre>
<p><strong>Get The Request URL</strong></p>
<pre class="prettyprint"><code>$url = Request::url();
</code></pre>
<p><strong>Retrieve A Request URI Segment</strong></p>
<pre class="prettyprint"><code>$segment = Request::segment(1);
</code></pre>
<p><strong>Retrieving A Request Header</strong></p>
<pre class="prettyprint"><code>$value = Request::header('Content-Type');
</code></pre>
<p><strong>Retrieving Values From $_SERVER</strong></p>
<pre class="prettyprint"><code>$value = Request::server('PATH_INFO');
</code></pre>
<p><strong>Determine If The Request Is Using AJAX</strong></p>
<pre class="prettyprint"><code>if (Request::ajax())
{
//
}
</code></pre>
<p><strong>Determining If The Request Is Over HTTPS</strong></p>
<pre class="prettyprint"><code>if (Request::secure())
{
//
}
</code></pre>
</article><div class="clearfix"></div>
</div>
</section>
<script src="js/jquery.min.js"></script>
<script src="js/plugins.js"></script>
<script type="text/javascript" src="vendor/google-code-prettify/run_prettify.js"></script>
</body></html>