php - Call to a member function name() on null in laravel 5.4 -


when pressing send button it's giving error this-

enter image description here

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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -