1

I'm trying to create a link in between 2 objects using NeoEloquent. Unfortunately i get the following error.

Class 'Permission' not found

NeoEloquent Error

I tried pretty much everything but i can't get it to work unfortunately.

I submit the permission objects I want to link to as an integer representing the id of the label.

The relationship between the labels is a Many to Many relation. As far as i can see i've done everything correctly. I've checked with the GitHub page, it looks good to me.

Thanks in advance!

Controller method:

/**
     * 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");
    }

Role Model:

<?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');
    }
}

Permission Model:

<?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 = [
    ];

}
djkevino
  • 264
  • 2
  • 16
  • 2
    Use the fully qualified name for `Permission` e.g. `"App\Permission"` or `Permission::class` with the appropriate `use` – apokryfos Feb 19 '18 at 17:28
  • @apokryfos i have tried that. Unfortunately Laravel then gives me Sorry, the page you are looking for could not be found all of a sudden with no real clue as to why, no entry in the log. When I analyse where it stops using dd(). It works just before the Attach function, after the attach it gives the page not found error. It also worked right before returning the hasMany relationship. – djkevino Feb 20 '18 at 05:43
  • 1
    Could not be found means a 404, meaning the permission in the request doesn't exist or attach doesn't find it properly. – apokryfos Feb 20 '18 at 09:01
  • @apokryfos I know, i have looked into the logs and found nothing. i have been trying things all day and eventually this worked: $test = \App\Permission::find($perm); $role->permissions()->attach($test); In the examples the ID should be sufficient. but with the object it now works. Thanks for the help :) – djkevino Feb 20 '18 at 17:20

0 Answers0