Route:
Route::post('admin/cms/create','CmsController@createmenu');
Controller action:
public function createmenu(Request $request){
$menu = new menu;
$this->validate($request,[
'name'=>'required',
's_title'=>'required_if:s_exist,1',
's_desc'=>'required_if:s_exist,1',
's_path'=>'required_if:s_exist,1',
'category'=>'required'
]);
$path=$request->file('s_path')->store('img/slideshow');
$menu::create([
'name'=>$request->name,
's_exist'=>$request->s_exist,
's_title'=>$request->s_title,
's_desc'=>$request->s_desc,
's_path'=>$path,
'category'=>$request->category
]);
return redirect('admin/cms');
}
Ajax (jquery):
$("#f_ins_menu").on("submit",function(e){
e.preventDefault();
var data={};
$.ajax({
type:"POST",
url:"cms/create",
data:$(this).serializeArray().map(function(x){data[x.name] = x.value;}),
contentType:false,
cache:false,
processData:false,
});
});
Createmenu action works without ajax
I have another action that uses Ajax and it works, but Request $requestI donβt pass the difference in this action , in fact I donβt miss anything.
I tried in native PHP and it works. Note that I added contentType:false, cache:false, processData:false,, because I also transfer the file.
I tried to die and dumb (dd) the $ request parameter, and I get a huge block of code, I think the class is, so my thoughts are that the Request $ request parameter does not receive the data that I pass through ajax
And yes, I enabled CSRF_FIELD with the meta tag trick I found here https://laravel.com/docs/5.4/csrf
- , , , , json, .
, , , . /.
public function createmenu(Request $request){
return dd($request);
}
, , , .
EDIT:
, HTTP- 422 HTTP- 500
2:
, die dumb (dd()) ajax, return . ajax, , @Lorav, :
data:{data:$(this).serialize()},
$data = $request->data;
Request, .