1

我正在尝试使用 NeoEloquent 在 2 个对象之间创建链接。不幸的是,我收到以下错误。

Class 'Permission' not found

NeoEloquent 错误

我几乎尝试了一切,但不幸的是我无法让它工作。

我将要链接到的权限对象作为表示标签 id 的整数提交。

标签之间的关系是多对多关系。据我所见,我做的一切都正确。我已经检查了 GitHub 页面,它对我来说看起来不错。

提前致谢!

控制器方法:

/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  Role  $role
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Role $role)
    {
        //dd($request);
        $this->validate($request, [
            'title' => 'required',
        ]);

        foreach($request['permission'] as $perm){
            $role->permissions()->attach($perm);
        }

        $role->title = request('title');

        $role->save();

        return redirect("/roles");
    }

好榜样:

<?php

namespace App;


use Vinelab\NeoEloquent\Eloquent\Model as NeoEloquent;



class Role extends NeoEloquent
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'title',
    ];

    protected $label = "Role";

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [

    ];

    public function permissions(){
        return $this->hasMany('Permission', 'Has_Permission');
    }
}

权限模型:

<?php

namespace App;


use Vinelab\NeoEloquent\Eloquent\Model as NeoEloquent;


class Permission extends NeoEloquent
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'title',
    ];

    protected $label = "Permission";

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
    ];

}
4

0 回答 0