聞きたいこと
現在Laravel5.5を使用して、Webアプリケーション開発をしています。
B to B(自分) to CのWeサービスなので、Userが
- エンドユーザー
- 法人
といった形で複数存在します。
そこでなのですが、Laravelで標準で存在しているUserモデルの名前などを、
- EndUser
- Company
などに変更しつつ、Laravel標準で使用できるUserの機能はいかしたいと思いっているのですが、ユーザー認証処理を実施した際に下のようなエラーに遭遇しました。
PHP
1Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) 2Class '\App\User' not found 3 4vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php
みた感じ、venderディレクトリにあるソースに手を加えなさそうなのですが、そもそもUserクラスの命名など変更すること自体まずいことなのでしょうか?(migrationファイルやモデルのnamespaceなどは変更済み)
可能であれば、既存のUserクラスの機能とほとんどおなじ機能をもつ、
- EndUser
- Company
などのUserクラス相当のものを作成したいとも思っています。
どなたかご存知の方、教えていただけたら嬉しいです。
[追記]
実際のコードを追記させていただきます。変更したファイルはマイグレーションファイルと、モデルの2ファイルのみです。
- 2014_10_12_000000_create_end_users_table.php
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateEndUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('end_users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->rememberToken(); $table->softDeletes(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('end_users'); } }
- App/Models/EndUser
<?php namespace App\Models; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use Tymon\JWTAuth\Contracts\JWTSubject; class EndUser extends Authenticatable implements JWTSubject { 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', ]; public function getJWTIdentifier() { return $this->getKey(); } public function getJWTCustomClaims() { return []; } }
回答2件
あなたの回答
tips
プレビュー