misicmali misicmali - 5 months ago 39
HTML Question

MethodNotAllowedHttpException in RouteCollection.php Laravel

I have problem to save name and email from user1 in table user1s that I have made .

When I enter them in textareas using html form in Laravel with

route::post
and function store it is not working. When I enter text and hit the button Register it outputs the following error:


MethodNotAllowedHttpException in RouteCollection.php line


You will see that I use the HTML form and that I have tried to add
<input ....>
into my form.




Here are my files:

route.php

<?php

Route::get('/','PageController@home');
Route::post('/','User1Controller@store');

Route::get('about','PageController@about');


welcome.blade.php

I'm not sure about the
action
.
After putting user1 inf into table, it should be redirected to a "Thank you" page (I have a thankyou.blade.php ) , maybe that is the problem

<form method="POST" action="">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>

<ul class="list-group" >


<li >
NAme
<div class="form-group" title="email" >
<textarea name="name" class="form-control" >

</textarea>
</div>
</li >

<li>Email
<div class="form-group" >
<textarea name="email" class="form-control" >

</textarea>
</div>
</li>

<li >
<div class="form-group" >
<button class="btn btn-primary">Register</button>
</div>
</li>

</ul>
</form>


migration for user1

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateNotesTable extends Migration
{

public function up()
{
Schema::create('notes', function (Blueprint $table) {
$table->increments('id');
$table->integer('card_id')->unsigned();
$table->text('body');
$table->timestamps();
});
}


public function down()
{
Schema::drop('notes');
}
}


user1controller.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User1;

class User1Controller extends Controller
{

public function store(Request $request)
{

$user= new User1;
$user->name = $request->name;
$user->email = $request->email;
$user->save();

return view('thankyou');

}

}


pagecontroller.php

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

use App\User1;

class PageController extends Controller
{
public function home()
{
$user1s= User1::all();
return view('welcome',compact('user1s'));
}

public function about()
{
return view('pages.about');
}

}

Answer

Your form is basically a registration form. I would recommend using a more meaningful name for the end point. The post route can be something like,

Route::post('/register','User1Controller@store');

Now the form action can be,

action="/register"