質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Q&A

0回答

574閲覧

laravel マルチログイン

Jojostyle

総合スコア11

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

0グッド

0クリップ

投稿2020/11/22 06:37

前提・実現したいこと

laravel5.4でシステムの改修行っています。
新たなユーザー区分を作り(admincompany)、まずそれらのloginやregisterをしたいです。Route [login] not defined.のエラーが出ています。

発生している問題・エラーメッセージ

Route [login] not defined.のエラー
名前付きルートをloginに変えるとcookieを消去を提案。
名前付きルートはできれば変えたくない。。。

該当のソースコード

companyadmin.php

<?php namespace App\Entities; use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Auth\User as Authenticatable; class CompanyAdmin extends Authenticatable { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; } ```web.php

Route::group(['prefix' => 'admincompany'], function () {

Route::get('login', 'AuthAdminCompany\LoginController@showLoginForm')->name('admin_company.login'); Route::post('login', 'AuthAdminCompany\LoginController@login')->name('admin_company.login'); Route::post('logout', 'AuthAdminCompany\LoginController@logout')->name('admin_company.logout'); Route::post('password/email', 'AuthAdminCompany\ForgotPasswordController@sendResetLinkEmail')->name('admin_company.password.email'); Route::get('password/reset', 'AuthAdminCompany\ForgotPasswordController@showLinkRequestForm')->name('admin_company.password.request'); Route::post('password/reset', 'AuthAdminCompany\ResetPasswordController@reset')->name('admin_company.password.update'); Route::get('password/reset/{token}', 'AuthAdminCompany\ResetPasswordController@showResetForm')->name('admin_company.password.reset'); });

logincontroller

1
<?php namespace App\Modules\User\Http\Controllers\AuthAdminCompany; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class LoginController extends Controller { /* |-------------------------------------------------------------------------- | Login Controller |-------------------------------------------------------------------------- | | This controller handles authenticating users for the application and | redirecting them to your home screen. The controller uses a trait | to conveniently provide its functionality to your applications. | */ use AuthenticatesUsers; /** * Where to redirect users after login. * * @var string */ protected $redirectTo = '/upload'; /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('auth:admin_company')->except('logout'); } public function showLoginForm(Request $request) { return view('User::admin_company.login'); } protected function guard() { return Auth::guard('admin_company'); } public function logout(Request $request) { $this->guard()->logout(); return redirect('/admincompany/login'); } } ```handler.php ```ここに言語を入力 protected function unauthenticated($request, AuthenticationException $exception) { if ($request->expectsJson()) { return response()->json(['error' => 'Unauthenticated.'], 401); } if (in_array('admincompany', $exception->guards(),true)) { return redirect()->guest(route('admin_company.login')); } return redirect()->guest(route('login')); } } ``````auth.php ```<?php return [ /* |-------------------------------------------------------------------------- | Authentication Defaults |-------------------------------------------------------------------------- | | This option controls the default authentication "guard" and password | reset options for your application. You may change these defaults | as required, but they're a perfect start for most applications. | */ 'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], /* |-------------------------------------------------------------------------- | Authentication Guards |-------------------------------------------------------------------------- | | Next, you may define every authentication guard for your application. | Of course, a great default configuration has been defined for you | here which uses session storage and the Eloquent user provider. | | All authentication drivers have a user provider. This defines how the | users are actually retrieved out of your database or other storage | mechanisms used by this application to persist your user's data. | | Supported: "session", "token" | */ 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', ], 'admin' => [ 'driver' => 'session', 'provider' => 'admins', ], 'admin_company' => [ 'driver' => 'session', 'provider' => 'admin_companies', ], ], /* |-------------------------------------------------------------------------- | User Providers |-------------------------------------------------------------------------- | | All authentication drivers have a user provider. This defines how the | users are actually retrieved out of your database or other storage | mechanisms used by this application to persist your user's data. | | If you have multiple user tables or models you may configure multiple | sources which represent each model / table. These sources may then | be assigned to any extra authentication guards you have defined. | | Supported: "database", "eloquent" | */ 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Entities\Member::class, ], 'admins' => [ 'driver' => 'eloquent', 'model' => App\Entities\Manager::class, ], 'admin_companies' => [ 'driver' => 'eloquent', 'model' => 'app\Entities\AdminCompany::class', ], // 'users' => [ // 'driver' => 'database', // 'table' => 'users', // ], ], /* |-------------------------------------------------------------------------- | Resetting Passwords |-------------------------------------------------------------------------- | | You may specify multiple password reset configurations if you have more | than one user table or model in the application and you want to have | separate password reset settings based on the specific user types. | | The expire time is the number of minutes that the reset token should be | considered valid. This security feature keeps tokens short-lived so | they have less time to be guessed. You may change this as needed. | */ 'passwords' => [ 'users' => [ 'provider' => 'users', 'email' => 'auth.emails.password', 'table' => 'password_resets', 'expire' => 60, ], 'admins' => [ 'provider' => 'admins', 'email' => 'auth.emails.password', 'table' => 'password_resets', 'expire' => 60, ], 'admin_companies' => [ 'provider' => 'admin_companies', 'email' => 'auth.emails.password', 'table' => 'password_resets', 'expire' => 60, ], ], ]; ``` ### 試したこと https://blog.hiroyuki90.com/articles/laravel%E3%81%A7%E3%83%9E%E3%83%AB%E3%83%81%E8%AA%8D%E8%A8%BC%EF%BC%88%E3%83%9E%E3%83%AB%E3%83%81%E3%83%AD%E3%82%B0%E3%82%A4%E3%83%B3%EF%BC%89%E3%81%AE%E5%AE%9F%E8%A3%85%E6%96%B9%E6%B3%95/ を元に実装 unauthenticatedが問題かと ### 補足情報(FW/ツールのバージョンなど) laravel5.4

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kyoya0819

2020/11/22 15:22

$ php artisan route:list の結果の追記をお願いします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問