2016-09-27 5 views
1

私は、laravel 5.3でビルドされたWebアプリケーションでロールとその権限を作成するのに、Zizaco/entrustの依存関係を使用しています。新しく作成された権限を保存しようとするたびに、私が抱えている問題は(タイトルが示すように)です。これはrolesテーブルに格納されています。Zizaco/entrust権限の保存にロールテーブルが使用されています

移行ファイルは、元のzizaco/entrustパッケージから変更されていません。私はphp artisan vendor:publishを使用して移行を作成しました。役割とパーミッションのモデルはかなりのドキュメントのようなものであると言う:

namespace App\Models; 

use Zizaco\Entrust\EntrustRole; 

class Role extends EntrustRole 
{ 

protected $table = 'roles'; 

/** 
* The attributes that are mass assignable. 
* 
* @var array 
*/ 
    protected $fillable = [ 
     'name', 'display_name', 'description', 
    ]; 
} 

と許可を

namespace App\Models; 

use Zizaco\Entrust\EntrustRole; 

class Permission extends EntrustRole 
{ 

protected $table = 'permissions'; 

/** 
* The attributes that are mass assignable. 
* 
* @var array 
*/ 
protected $fillable = [ 
     'name', 'display_name', 'description', 
    ]; 
} 

とシーダファイルで、私は役割とシーダ生成するには、次のコードを使用します。

use App\Models\Permission; 
use App\Models\Role; 
use Illuminate\Database\Seeder; 

class RoleSeeder extends Seeder 
{ 
/** 
* Run the database seeds. 
* 
* @return void 
*/ 
public function run() 
{ 
    $owner = new Role(); 
    $owner->name   = 'owner'; 
    $owner->display_name = 'Eigenaar'; 
    $owner->save(); 

    $createOwner = new Permission(); 
    $createOwner->name   = 'create-owner'; 
    $createOwner->display_name = 'Eigenaar toevoegen'; 
    $createOwner->save(); 
} 

また、entrustの設定ファイルも、役割と権限モデルの正しいパスとテーブルにも変更されています。

私は作者dump-autoloadやPHP artisan cacheをクリアしようとしました。

私が見逃したことはありますか?助けてください。 文法上正しくない場合は、私の英語を赦免してください。

編集:私は次の行でロールに私の許可を添付しようとすると:

$owner->attachPermission($createOwner); 

私は、SQLエラーを取得する:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fail s (reunions_dev . permission_role , CONSTRAINT permission_role_permission_id_foreign FOREIGN KEY (permission_id) REFERENCES permissions (id) ON DELETE CASCADE ON UPDATE CASCADE)

許可のレコードがないためでありますIDをリンクするちょっと明白。

答えて

0

The problem I am having is (as the title says) whenever I try to save a newly created Permission. It is stored in the roles table.

あなたが提供したコードを見ると、Permissionモデルのクラスが間違っています。 EntrustPermissionにご許可モデルでクラスを拡張use文&を変更します。

use Zizaco\Entrust\EntrustPermission; 

class Permission extends EntrustPermission 
+0

ありがとうは私のコードで一目を取るため。私はそれを前に見たことがないと信じられない!私は今tho別のエラーを取得しています。シーダークラスで初期化しようとするたびに、エラーが表示され続けます。 'Required parameter $ auth missing'それをどのように修正できるか知っていますか? – Hoffie

関連する問題