Here is the code of HTML Form
<form method="POST" action={{ route('store') }} class="col s12">
@csrf
<div class="row">
<div class="input-field col s6">
<input name="task" id="task" type="text" class="validate">
<label for="task">New Task</label>
</div>
</div>
@include('partials.coworkers')
<button type="submit" class="waves-effect waves-light btn">Add Task</button>
</form>
@isWorker
<br><br><br>
<form action="" class="col s6">
<div class="row">
<div class="input-field col s6">
<select>
<option value="" disabled selected>Send Invitation To</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Send Invitation</label>
</div>
</div>
<a class="waves-effect waves-light btn">Send Invitation</a>
</form>
Here is my code for store method inside a controller.
public function store(Request $request){
if ($request->input('task')) {
$task = new Task;
$task->content = $request->input('task');
Auth::user()->tasks()->save($task);
}
return redirect()->back();
}
web.php:
Route::middleware(['auth'])->group(function(){
Route::get('/', 'CrudApp@index');
Route::get('/store', 'CrudApp@store')->name('store');
Route::get('/edit/{id}', 'CrudApp@edit')->name('edit');
Route::get('/update/{id}', 'CrudApp@update')->name('update');
Route::get('/delete/id', 'CrudApp@delete')->name('delete');
});
I want to store the task into database. as soon as I hit save MethodNotAllowedHTTPException
occurs and i am unable to figure out how to resolve the issue.
First of all:
php artisan route:cache
make it after any changes in route file (web.php in your case).
And now your code. Look u use POST:
<form method="POST" action={{ route('store') }} class="col s12">
so change:
Route::get('/store', 'CrudApp@store')->name('store');
on:
Route::post('/store', 'CrudApp@store')->name('store');