Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel get POSTed data using request

Tags:

php

laravel

In Laravel how do I get the request body? I am trying $request->get(‘data’) but I get a null result. I am doing a POST request to a store function in my controller but I am unable to get the POSTed data.

public function store(Request $request)
{
    $test = $request->get('data');

}
like image 945
ZeroCode Avatar asked Dec 04 '22 19:12

ZeroCode


2 Answers

Retrieving All Input Data

$data = $request->all();

Retrieving An Input Value

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

Retrieving An Input Value with default value

$name = $request->input('name', 'Sally');

For details read Laravel document here https://laravel.com/docs/5.6/requests

like image 191
rkj Avatar answered Dec 11 '22 16:12

rkj


In Laravel, you can fetch the request input data by using $request->all(). This will then return the input data as an array. You can find more in the docs here.

like image 39
liamjnorman Avatar answered Dec 11 '22 17:12

liamjnorman