1

I'm a newbie to this laravel.

i've followed a tutorial and i've checked that i wasn't do anything wrong, and then this error comes up. in this code i tried to Read data from table Inputs and create a page to Insert Data into the database in Inputs table.

TicketController:

public function index(){
    $inputs = Inputs::all();
    return view('index', [
        'inputs' => $inputs
    ]);
}
public function create(){
    return view('create');
}
public function store(Request $request)
{
    $inputs = new Inputs();

    $inputs->inputName = $request->inputName;
    $inputs->inputAddress = $request->inputAddress;
    $inputs->inputBDO = Carbon::parse($request->inputBDO);
    $inputs->inputEmail = $request->inputEmail;
    $inputs->inputPhone = $request->inputPhone;
    $inputs->inputJob = $request->inputJob;

    $inputs->save();

    return redirect('/input');
}

}

Routes:

Route::get('/', 'TicketController@index');
Route::get('/input/create', 'TicketController@create');
Route::post('/input', 'TicketController@store');
1
  • 2
    Post your blade view code as well Commented Jul 2, 2018 at 6:53

2 Answers 2

2

In laravel MethodNotAllowedHttpException comes when you are referring a route which is not available or its type is mismatch. In your case the issue is same, and it is:

return redirect('/input');

&

Route::post('/input', 'TicketController@store');

for the first time when you are posting the from at that time the route method match, but at the time of redirection it is looking for:

Route::get('/input', 'TicketController@store');

which is not present, that's why the error.

Sign up to request clarification or add additional context in comments.

2 Comments

In that case use return redirect('/');
Thanks. Helped me to understand the proper use of "routes"
1

You are redirecting back to /input at the end of your store() function. A redirect is done using a GET request, but you only have a POST route assigned to this url.

Route::post('/input', 'TicketController@store');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.