###前提・実現したいこと
Mac OS Sierra
Laravel5.5 Homestead
Database mysql
vagrant
virtualbox
Sequel Pro
環境下で、「php artisan make:auth」コマンドを入力して自動生成される
passport.dev/registerのページで、ユーザー登録が出来ないので、DBにSeederを
使わずに、ユーザー登録をしたい。
「Seederを使用して、ダミーデータを作成してGUI Databaseツール:Sequel Proでデータ挿入されているのは確認済み」
※参考ブログや、URL
1.API認証(Passport)機能の動作確認
(この記事のpassport.dev/registerでの認可ではなく、認証(make:auth使用)が実装できない)
http://www.dn-web64.com/archives/web/laravel_passport/
2.Laravel 5.4 の認証機能とそのカスタマイズ
(この記事より、1.API認証(Passport)の為の認証を実装しようと参考にしている)
https://qiita.com/naga3/items/4f3defde59b31a1a797e
3.Laravel5.4でマルチ認証(userとadmin)を実装する方法
https://takahashi-it.com/php/laravel54-multi-auth/#step-1
単純に、auth認証が作りたいだけなのですが、初めて認証機能を実装しようとしている為、何が足らないのか、わからないので何卒教えていただきたいです。
###発生している問題・エラーメッセージ
挙動は、バリデーションは、min:6にしてUserIDをそれ未満の文字にした場合に、しっかりかかるので フロントのビューは問題なさそうです。 しかし、2.Laravel 5.4 の認証機能とそのカスタマイズ (この記事より、1.API認証(Passport)の為の認証を実装しようと参考にしている) https://qiita.com/naga3/items/4f3defde59b31a1a797e の記事と全く一緒の編集作業を行っても、データベースに登録されず、/registerに、useridと、emailの値を保持して、 passwordだけ再入力の状態でまたページ遷移されて戻ってくる。 php artisan migrate:fresh --seedで、Seederのテストデータを使用して、Loginコントローラーから、ログインのダミーデータを使用してログインしようとしても、それも出来ない為、Databaseの設定の問題と思われます。
###該当のソースコード
/database/migrations/2017_12_01_051211_update_users_table.php は、2.Laravel 5.4 の認証機能とそのカスタマイズと同様なので、省略
.env DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=test_business_trip DB_USERNAME=homestead DB_PASSWORD=secret
routes/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'); }); Auth::routes(); Route::get('/home', 'HomeController@index')->name('home'); /* |-------------------------------------------------------------------------- | 1) User 認証不要 |-------------------------------------------------------------------------- */ Route::get('/', function () { return redirect('/home'); }); /* |-------------------------------------------------------------------------- | 2) User ログイン後 |-------------------------------------------------------------------------- */ Route::group(['middleware' => 'auth:user'], function() { Route::get('/home', 'HomeController@index')->name('home'); }); /* |-------------------------------------------------------------------------- | 3) Admin 認証不要 |-------------------------------------------------------------------------- */ Route::group(['prefix' => 'admin'], function() { Route::get('/', function () { return redirect('/admin/home'); }); Route::get('login', 'Admin\LoginController@showLoginForm')->name('admin.login'); Route::post('login', 'Admin\LoginController@login'); }); /* |-------------------------------------------------------------------------- | 4) Admin ログイン後 |-------------------------------------------------------------------------- */ Route::group(['prefix' => 'admin', 'middleware' => 'auth:admin'], function() { Route::post('logout', 'Admin\LoginController@logout')->name('admin.logout'); Route::get('home', 'Admin\HomeController@index')->name('admin.home'); });
app/Http/HomeController <?php namespace App\Http\Controllers; use Illuminate\Http\Request; class HomeController extends Controller { /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('auth'); } /** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { return view('home'); } }
app/Http/Auth/RegisterController.php は、2.Laravel 5.4 の認証機能とそのカスタマイズと同様なので、省略
resources/views/auth/register.blade.php @extends('layouts.app') @section('content') <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> <div class="panel-heading">Register</div> <div class="panel-body"> <form class="form-horizontal" method="POST" action="{{ route('register') }}"> {{ csrf_field() }} <div class="form-group{{ $errors->has('userid') ? ' has-error' : '' }}"> <label for="userid" class="col-md-4 control-label">User ID</label> <div class="col-md-6"> <input id="userid" type="text" class="form-control" name="userid" value="{{ old('userid') }}" required autofocus> @if ($errors->has('userid')) <span class="help-block"> <strong>{{ $errors->first('userid') }}</strong> </span> @endif </div> </div> <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}"> <label for="email" class="col-md-4 control-label">E-Mail Address</label> <div class="col-md-6"> <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required> @if ($errors->has('email')) <span class="help-block"> <strong>{{ $errors->first('email') }}</strong> </span> @endif </div> </div> <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> <label for="password" class="col-md-4 control-label">Password</label> <div class="col-md-6"> <input id="password" type="password" class="form-control" name="password" required> @if ($errors->has('password')) <span class="help-block"> <strong>{{ $errors->first('password') }}</strong> </span> @endif </div> </div> <div class="form-group"> <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label> <div class="col-md-6"> <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required> </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> Register </button> </div> </div> </form> </div> </div> </div> </div> </div> @endsection
/app/Http/Middleware/RedirectIfAuthenticated.php は、2.Laravel 5.4 の認証機能とそのカスタマイズと同様なので、省略
app/User.php は、2.Laravel 5.4 の認証機能とそのカスタマイズと同様なので、省略
MySQL Database test_business_tripデータベースの usersテーブル CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `userid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `users_email_unique` (`email`), UNIQUE KEY `users_userid_unique` (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
長くなりましたが、以上が添付ソースコードになります。
また必要な情報があれば、随時更新していくので、どうか皆さまお力をお貸しください!!!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/04 02:02
退会済みユーザー
2017/12/04 02:09
2017/12/04 02:14