Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Trying to save a polymorphic relationship yields ErrorException #289

Open
zakiaziz opened this issue Jan 3, 2016 · 0 comments
Open

Trying to save a polymorphic relationship yields ErrorException #289

zakiaziz opened this issue Jan 3, 2016 · 0 comments

Comments

@zakiaziz
Copy link

zakiaziz commented Jan 3, 2016

The error I'm receiving:

ErrorException in Ardent.php line 821:
Invalid argument supplied for foreach()

Models:

class ModelOne extends Ardent
{
    public function modelThree()
    {
        return $this->morphToMany('App\ModelThree', 'modelthreeable');
    }
}

class ModelTwo extends Ardent
{
    public function modelThree()
    {
        return $this->morphToMany('App\ModelThree', 'modelthreeable');
    }   

}

class ModelThree extends Ardent
{
    public function modelOne()
    {
        return $this->morphedByMany('App\ModelOne', 'modelthreeable');
    }

    public function modelTwo()
    {
        return $this->morphedByMany('App\ModelTwo', 'modelthreeable');
    } 
}

Controller:

class ModelThreeController extends Controller
{
    public function store(Request $request)
    {
        $modelThree = new modelThree;
        $modelThree->name = $request->input('amount', NULL);

        $modelOne = App\ModelOne::find($modelOneId);
        $modelOne->modelThree()->save($modelThree);
    }
}

(I'm aware in the code above ModelTwo is not being touched)

@zakiaziz zakiaziz changed the title Trying to save a polymorphic relationship yields Trying to save a polymorphic relationship yields ErrorException Jan 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant