php - Call to a member function name() on null in laravel 5.4 -
when pressing send button it's giving error this-
here routes web.php bellow-
route::group(['prefix'=>'ajax', 'as'=>'ajax::'], function() { route::resource('message/send', 'messagecontroller@ajaxsendmessage')->name('message.new'); route::delete('message/delete/{id}', 'messagecontroller@ajaxdeletemessage')->name('message.delete'); });
here controller messagecontroller.php bellow:
public function ajaxsendmessage(request $request) { if ($request->ajax()) { $rules = [ 'message-data'=>'required', '_id'=>'required' ]; $this->validate($request, $rules); $body = $request->input('message-data'); $userid = $request->input('_id'); if ($message = talk::sendmessagebyuserid($userid, $body)) { $html = view('ajax.newmessagehtml', compact('message'))->render(); return response()->json(['status'=>'success', 'html'=>$html], 200); } } }
resource routes should named differently:
route::prefix('ajax')->group(function () { route::resource('messages', 'messagecontroller', ['names' => [ 'create' => 'message.new', 'destroy' => 'message.destroy', ]]); });
resource routes point controller, instead of specific method. in messagecontroller, should add create , destroy methods.
more info @ https://laravel.com/docs/5.4/controllers#restful-naming-resource-routes
Comments
Post a Comment