Remove a key from the request input in Laravel

July 25, 2022  ‐ 1 min read

From the data that is submitted to the controller we often can save all the fields to the model. In some cases a field doesn't belong to the model, we wish to use it for something else.

In such a case we can remove the field from the request data. By using the remove() method for instance.

<?php

public function store(Request $request)
{
    $request->request->remove('input_field');
}

Or we can retrieve the inputs except for a given set of fields.

<?php

public function store(Request $request)
{
    $data = $request->except(['input_field']);
}