laravelを用いて新規登録画面、ログイン画面を作成しようと思っているのですが
新規登録画面の作成のステップでつまずいています。
(laravel学習帳/チュートリアル/中級/認証画面の自作を参考に作成しています)
登録画面を作成し、新規登録を行おうとすると
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
というエラーが発生します。
このエラーが発生した場合ルーティングの部分が間違っている可能性が高いと調べたのですが、どの部分が間違っているのか自分で見つけることが出来ません。
またデータベースにも反映されません。データベースはsqliteを使用しています
よろしくお願いします。
laravelのバージョンは5.5.44です。
以下がコードになります。
UserController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\User; class UserController extends Controller { public function getSignup(){ return view('user.signup'); } public function postSignup(Request $request){ $this->validate($request,[ 'name' => 'required', 'namek' => 'required', 'mail' => 'email|required|unique:users', 'password' => 'required|min:4', 'address' => 'required', 'birth' => 'required', ]); $user = new User([ 'name' => $request->input('name'), 'namek' => $request->input('namek'), 'address' => $request->input('address'), 'birth' => $request->input('birth'), 'mail' => $request->input('mail'), 'password' => bcrypt($request->input('password')), ]); $user->save(); return redirect()->route('user.profile'); } public function getProfile(){ return view('user.profile'); } }
web.php <?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); /*Route::get('user/signup', 'UserController@getSignup'); Route::post('user/signup', 'UserController@postSignup'); Route::get('user/profile', 'UserController@getProfile');*/ Route::group(['prefix' => 'user'], function() { Route::get('/signup',[ 'uses' => 'UserController@getSignup', 'as' => 'user.signup' ]); Route::post('/signup',[ 'uses' => 'UserController@postSignup', 'as' => 'user.signup' ]); Route::post('/profile',[ 'uses' => 'UserController@getProfile', 'as' => 'user.profile' ]); });
User.php <?php namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'namek','address', 'birth', 'mail', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'id', //'remember_token', ]; }
2019_01_25_050924_create_user_table.php <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateUserTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('user', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); $table->string('name'); $table->string('namek'); $table->string('address'); $table->string('birth'); $table->string('mail'); $table->string('password'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('user'); } }
master_auth.blade.php <!DOCTYPE HTML> <html lang="ja"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>@yield('title')</title> <link href="{{ url('/') }}/dist/css/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"><!-- Loading Bootstrap --> <link href="{{ url('/') }}/dist/css/flat-ui.min.css" rel="stylesheet"><!-- Loading Flat UI --> <link href="{{ url('/') }}/css/starter-template.css" rel="stylesheet"><!--Bootstrap theme(Starter)--> <link rel="shortcut icon" href="{{ url('/') }}/dist/img/favicon.ico"> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> @yield('styles') </head> <body> @include('partials.header') <div class="container"> @yield('content') </div><!-- /.container --> <footer class="footer"> <div class="container"> <p class="text-muted">認証デモ</p> </div> </footer> <!-- Bootstrap core JavaScript ================================================== --> <script src="{{ url('/') }}/dist/js/vendor/jquery.min.js"></script> <script src="{{ url('/') }}/dist/js/vendor/video.js"></script> <script src="{{ url('/') }}/dist/js/flat-ui.min.js"></script> <script src="{{ url('/') }}/assets/js/prettify.js"></script> <script src="{{ url('/') }}/assets/js/application.js"></script> @yield('scripts') </body> </html>
signup.blade.php @extends('layouts.master_auth') @section('content') <div class="row"> <form action= "/touroku/public/user/profile" method="post" class="form-horizontal" style="margin-top: 50px;"> <div class="form-group"> <label class="col-sm-3 control-label" for="InputName">氏名</label> <div class="col-sm-9"> <input type="text" name="name" class="form-control" id="InputName" placeholder="氏名"> <!--/.col-sm-10---></div> <!--/form-group--></div> <div class="form-group"> <label class="col-sm-3 control-label" for="InputNamek">氏名(カタカナ)</label> <div class="col-sm-9"> <input type="" name="namek" class="form-control" id="InputNamek" placeholder=""> </div> <!--/form-group--></div> <div class="form-group"> <label class="col-sm-3 control-label" for="InputAddress">住所</label> <div class="col-sm-9"> <input type="" name="address" class="form-control" id="InputAddress" placeholder="番地まで"> </div> <!--/form-group--></div> <div class="form-group"> <label class="col-sm-3 control-label" for="InputBirth">生年月日</label> <div class="col-sm-9"> <input type="" name="birth" class="form-control" id="InputBirth" placeholder=""> </div> <!--/form-group--></div> <div class="form-group"> <label class="col-sm-3 control-label" for="InputEmail">メール・アドレス</label> <div class="col-sm-9"> <input type="email" name="mail" class="form-control" id="InputMail" placeholder=""> </div> <!--/form-group--></div> <div class="form-group"> <label class="col-sm-3 control-label" for="InputPassword">パスワード</label> <div class="col-sm-9"> <input type="password" name="password" class="form-control" id="InputPassword" placeholder=""> </div> <!--/form-group--></div> <div class="form-group"> <div class="col-sm-offset-3 col-sm-9"> <button type="submit" class="btn btn-primary btn-block">新規登録</button> </div> <!--/form-group--></div> {{ csrf_field() }} </form> </div> @endsection
profile.blade.php @extends('layouts.master_auth') @section('content') <div style="margin-top: 30px; text-align: center;"><h3>新規登録完了しました。</h3></div> @endsection
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/27 07:36