I have a form that sends a request through Ajax in laravel
This snippet from my controller returns null
use Illuminate\Http\Request;
class StatusController extends Controller {
public function postStatus(Request $request) {
if ($request->ajax()) {
dd($request->input('statusBody'));
This however returns an array with statusBody
as a key name with null value
use Illuminate\Http\Request;
class StatusController extends Controller {
public function postStatus(Request $request) {
if ($request->ajax()) {
dd($request->input());
This is the returned result
array:1 [▼
"This_is_a_sample_status" => null
]
And this finally returns the correct value
use Illuminate\Http\Request;
class StatusController extends Controller {
public function postStatus(Request $request) {
if ($request->ajax()) {
$val = $request->input('statusBody');
dd(array_search($val, $request->all()));
My question is: Why does this happen?
Why doesn't $request->input('name')
returns a value as expected?
UPDATE:
This is also the Ajax function which successfully logs the wanted result to the console
var statusBody = $('#statusBody').val();
$.ajax({
type: "POST",
url: 'status',
data: statusBody,
success: function(data){
console.log(statusBody);
}
});