What is a Laravel Request ?

Commissioning the back end series

Created on: April 01, 2018

Updated on: April 01, 2018

Tip of the week

What is a request in Laravel ?

A Laravel request is a means of retrieving the input data that has been sent within a form. It is in the form of a http request. The request data usually contains the fields of the model that is used to collect the data.

We use Laravel request data within our web development services back end applications. They are an important component within the development of web applications.

If the request isn’t declared, this can create future problems down the line because we depend on this data in order to inject our dependency in to the IOC container.

The best way to illustrate this is to look at an actual request.

class BlogRequest extends FormRequest
     * Determine if the user is authorized to make this request.
     * @return bool
    public function authorize()
        return true;

     * Get the validation rules that apply to the request.
     * @return array
    public function rules()
        return [
            'title' => 'required|min:3',
            'series' => 'required|min:3',
            'body' => 'required',
            'published_at' => 'required',
            'feat_image' => 'required'



Authorize function

All requests have an authorize function and this is set to false as a default on new applications. In our case, we have set this to true because we are using the request within the web development services example.

Rules function

Our rules function contains a series of fields from our blog model. Just below it we have a return function, where we have a list of fields on the left and the corresponding formats on the right hand side. One thing to note is that we have the format that they request is expecting on the right hand side.

The title and the series can expect to have a minimum of 3 characters and it is a required field which means that the user has to input something in to these fields in the forms that are created. If they don’t then this will generate an error (we usually use error bags to display the errors to the user).

We hope that you have learn't how you can set up fields within a request.

Stay tuned for further tips and tricks from www.ormrepo.co.uk/blogs. The link also provides information about the web development services we offer.