Atom Framework
Go to Github
v1.0.0
v1.0.0
  • Installation
  • Getting Started
  • Configuration
    • Environment
    • Authentication
  • Basics
    • Routing
    • Middleware
    • Controllers
    • Models
    • Requests
    • Views
    • URL Generation
    • Session
  • Misc
    • Security
      • Encryption
      • Hashing
    • Storage
    • Moment
Propulsé par GitBook

© 2025 Licon Corp

Sur cette page
  • Accessing The Request
  • Request Parameters & Method
  • Retrieving Method
  • Retrieving parameter
  • Retrieving Inputs
  • Retrieving Portion Of The Input Data
  • Flash
  • Retrieving Cookie From Request
  • Files
  • Retrieving Uploaded Files
  • File Properties
  • Storing Uploaded Files

Cet article vous a-t-il été utile ?

  1. Basics

Requests

Handling HTTP Requests

Accessing The Request

To obtain an instance of the current HTTP request, you should use the request helper method:

// Get title from the user inputs
$title = request('title');

//or
$title = request()->input('title');

Using request() without passing any arguments will return the current request instance.

Request Parameters & Method

Retrieving Method

The method method returns the request method:

$method = request()->method();

Retrieving parameter

The params method returns the request/server parameter with the given key or returns all the request/server parameters if there's no key:

$port = request()->params('SERVER_PORT');

$all = request()->params();

Retrieving Inputs

If you want to get all request input:

$input = request()->input();

If you want to get an input value:

$title = request('title');

or

$title = request()->input('title');

You may pass a default value as the second argument to the input method. This value will be returned if the requested input value is not present on the request:

$title = request('title', 'Default Title');
$title = request()->input('title', 'Default Title');

Retrieving Portion Of The Input Data

If you need to retrieve a subset of the input data, you may use the only and except methods. Both of these methods accept a single array or a dynamic list of arguments:

$input = request()->only(['username', 'password']);

$input = request()->only('username', 'password');

$input = request()->except(['credit_card']);

$input = request()->except('credit_card');

Flash

The flash method will flash a message to the current session so that it is available during the user next request:

request()->flash('Incorrect login information.', 'error');

Retrieving Cookie From Request

All cookies created by the Atom framework are encrypted and signed with an authentication code, meaning they will be considered invalid if they have been changed by the client. To retrieve a cookie value from the request, use the cookiemethod on a request instance:

$value = request()->cookie('name');

Files

Retrieving Uploaded Files

You may access uploaded files from a Atom\Request\Request instance using the files method or file method. The file method returns an instance of the Atom\Request\UploadedFile class, which provides a variety of methods for interacting with the file:

$files = request()->files();

$file = request()->file('photo');

File Properties

The UploadedFile class also contains the get method for accessing the file properties. For example:

$photo = request()->file('photo');

$name = $photo->name;
$size = $photo->size;
$extension = $photo->get('extension');

Here is a list of all file properties:

Property

Description

name

Name of the uploaded file

type

Type of the uploaded file

size

Size of the uploaded file

extension

Extension of the uploaded file

tmp_name

Temporary path to the uploaded file

real_path

Path to the file uploaded on your server

real_name

Name of the file uploaded on your server

Storing Uploaded Files

To store an uploaded file, you will typically use one of your configured storage. The UploadedFile class has a store and storeAs method which will move an uploaded file to one of your disks, which may be a location on your local filesystem.

The store method accepts an optionalpublic argument which determine if the file should be publicly accessible and an second optional serialize argument which determine if the file contents should be serialized. By default, the file is not publicly accessible and the contents of the file will not be serialized:

A unique ID will automatically be generated to serve as the file The method will return the uploaded file or false if file wasn't uploaded:

$file = request()->file('photo')->store();

// Store the file publicly...
$file = request()->file('photo')->store(true);

// Serialize the stored file
$file = request()->file('photo')->store(true, true);

If you do not want a file name to be automatically generated, you may use the storeAs method, which accepts the file name, public storage, and serialization as its arguments:

// Store as my_image, publicly and not serialized...
$file = request()->file('photo')->storeAs('my_image', true, false);

PrécédentModelsSuivantViews

Dernière mise à jour il y a 6 ans

Cet article vous a-t-il été utile ?

All parameters available

here