I have been trying to complete an ajax request. However the form submission is giving me error 500. I created a controller to process the form submission. at first i thought the problem was due to _token. But i added token and problem was not fixed. Then i changed my post route and processed the request on the route page and this seems to work. I still want to use a controller to process the form submission.
Routes
//this does not
Route::post('/mail',[
'uses'=>'ContactController@postContact',
'as'=>'postContact'
]);
//this works
Route::post('/mail2',function(){
return response()->json([
'result'=>'success'
]);
});
Problem controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\ContactModel;
class ContactController extends Controller
{
public function getContactList()
{
$contacts = Contact::all();
return response()->json([
'contacts'=>$contacts
]);
}
public function postContact(Requests $request)
{
return response()->json([
'result'=>'success'
]);
}
}
Any idea whats going on?
Fixed: It was a typo guys.
public function postContact(Request $request)
{
return response()->json([
'result'=>'success'
]);
}