Required With Laravel Input and Uploaded File

Icon

Alarm You're browsing the documentation for an former version of Laravel. Consider upgrading your project to Laravel 9.x.

Requests & Input

  • Basic Input
  • Cookies
  • Old Input
  • Files
  • Request Information

Basic Input

Yous may access all user input with a few simple methods. You practice not need to worry nearly the HTTP verb used for the request, as input is accessed in the same way for all verbs.

Retrieving An Input Value

                                  

$proper name = Input :: go ( ' proper noun ' );

Retrieving A Default Value If The Input Value Is Absent

                                  

$name = Input :: go ( ' name ' , ' Sally ' );

Determining If An Input Value Is Present

                                  

if ( Input :: has ( ' proper noun ' ))

{

//

}

Getting All Input For The Request

                                  

$input = Input :: all ();

Getting Just Some Of The Request Input

                                  

$input = Input :: merely ( ' username ' , ' countersign ' );

$input = Input :: except ( ' credit_card ' );

When working on forms with "assortment" inputs, y'all may employ dot notation to admission the arrays:

                                  

$input = Input :: get ( ' products.0.proper name ' );

Note: Some JavaScript libraries such as Backbone may send input to the awarding as JSON. You may admission this data via Input::get like normal.

Cookies

All cookies created by the Laravel framework are encrypted and signed with an authentication code, pregnant they will be considered invalid if they have been changed by the customer.

Retrieving A Cookie Value

                                  

$value = Cookie :: get ( ' name ' );

Attaching A New Cookie To A Response

                                  

$response = Response :: make ( ' How-do-you-do Globe ' );

$response -> withCookie ( Cookie :: brand ( ' proper name ' , ' value ' , $minutes ));

Queueing A Cookie For The Next Response

If y'all would like to set a cookie before a response has been created, use the Cookie::queue() method. The cookie will automatically be attached to the final response from your awarding.

                                  

Cookie :: queue ( $proper name , $value , $minutes );

Creating A Cookie That Lasts Forever

                                  

$cookie = Cookie :: forever ( ' name ' , ' value ' );

Old Input

You lot may need to continue input from 1 request until the side by side request. For example, you may need to re-populate a grade subsequently checking it for validation errors.

Flashing Input To The Session

                                  

Input :: flash ();

Flashing But Some Input To The Session

                                  

Input :: flashOnly ( ' username ' , ' email ' );

Input :: flashExcept ( ' password ' );

Since y'all often volition want to wink input in association with a redirect to the previous page, y'all may easily concatenation input flashing onto a redirect.

                                  

return Redirect :: to ( ' class ' ) -> withInput ();

return Redirect :: to ( ' form ' ) -> withInput ( Input :: except ( ' password ' ));

Note: You may flash other data across requests using the Session class.

Retrieving Old Data

                                  

Input :: old ( ' username ' );

Files

Retrieving An Uploaded File

                                  

$file = Input :: file ( ' photo ' );

Determining If A File Was Uploaded

                                  

if ( Input :: hasFile ( ' photograph ' ))

{

//

}

The object returned by the file method is an instance of the Symfony\Component\HttpFoundation\File\UploadedFile class, which extends the PHP SplFileInfo form and provides a variety of methods for interacting with the file.

Determining If An Uploaded File Is Valid

                                  

if ( Input :: file ( ' photo ' ) -> isValid ())

{

//

}

Moving An Uploaded File

                                  

Input :: file ( ' photo ' ) -> move ( $destinationPath );

Input :: file ( ' photograph ' ) -> move ( $destinationPath , $fileName );

Retrieving The Path To An Uploaded File

                                  

$path = Input :: file ( ' photograph ' ) -> getRealPath ();

Retrieving The Original Proper noun Of An Uploaded File

                                  

$proper noun = Input :: file ( ' photo ' ) -> getClientOriginalName ();

Retrieving The Extension Of An Uploaded File

                                  

$extension = Input :: file ( ' photo ' ) -> getClientOriginalExtension ();

Retrieving The Size Of An Uploaded File

                                  

$size = Input :: file ( ' photograph ' ) -> getSize ();

Retrieving The MIME Type Of An Uploaded File

                                  

$mime = Input :: file ( ' photograph ' ) -> getMimeType ();

Request Data

The Asking form provides many methods for examining the HTTP request for your application and extends the Symfony\Component\HttpFoundation\Request class. Here are some of the highlights.

Retrieving The Asking URI

                                  

$uri = Request :: path ();

Retrieving The Asking Method

                                  

$method = Request :: method ();

if ( Request :: isMethod ( ' post ' ))

{

//

}

Determining If The Request Path Matches A Pattern

                                  

if ( Request :: is ( ' admin/* ' ))

{

//

}

Get The Request URL

                                  

$url = Asking :: url ();

Retrieve A Asking URI Segment

                                  

$segment = Request :: segment ( 1 );

Retrieving A Request Header

                                  

$value = Asking :: header ( ' Content-Type ' );

Retrieving Values From $_SERVER

                                  

$value = Request :: server ( ' PATH_INFO ' );

Determining If The Request Is Over HTTPS

                                  

if ( Request :: secure ())

{

//

}

Determine If The Request Is Using AJAX

                                  

if ( Request :: ajax ())

{

//

}

Determine If The Asking Has JSON Content Type

                                  

if ( Asking :: isJson ())

{

//

}

Determine If The Request Is Asking For JSON

                                  

if ( Asking :: wantsJson ())

{

//

}

Checking The Requested Response Format

The Request::format method will return the requested response format based on the HTTP Take header:

                                  

if ( Request :: format () == ' json ' )

{

//

}

ashleyhecting.blogspot.com

Source: https://laravel.com/docs/4.2/requests

0 Response to "Required With Laravel Input and Uploaded File"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel