Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ozan's avatar
Level 32

Managing Mass User Settings

I did exactly the same things as @JeffreyWay did and I get this error.

  [LogicException]
  Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
0 likes
21 replies
pmall's avatar

You need to give more details and show some code man :)

1 like
mstnorris's avatar

Did you put the following in your model?

protected $casts = [ ... ];
toniperic's avatar

I did exactly the same things as JeffreyWay did and I get this error.

Apparently you haven't. :)

1 like
Ozan's avatar
Level 32

@pmall

//user model
protected $casts = [
    'details' => 'json',
];

public function details()
{
    return new Details($this);
}
// Details class
class Details {
    
    protected $user;

    protected $allowed = [
        'name', 
        'address',
        'biography',
    ];

    function __construct(User $user) {
        $this->user = $user;
    }

    public function merge(array $attributes)
    {
        $details_array = array_merge(
            $this->user->details, 
            array_only($attributes, $this->allowed)
        );

        return $this->user->update(compact('details_array'));
    }

}
$user->details()->merge($request->all());
mstnorris's avatar

@Ozan are you using the latest development version of Laravel? To double check run

php artisan
Ozan's avatar
Level 32

5.0.28 updating now thanks ... see? I did the exact same thing :D

1 like
Ozan's avatar
Level 32

Laravel Framework version 5.0.31

pmall's avatar

What do you want to achieve here ?

mstnorris's avatar
Level 55

You need

"laravel/framework": "5.1.*"
mstnorris's avatar

@Ozan it is the development version, Jeffrey says so at the beginning of the video. It will be released soon.

mstnorris's avatar

@pmall, @Ozan is following Jeffrey's latest lesson on Mass User Settings. He was just using the wrong (older) version of Laravel.

Kryptonit3's avatar

I watched the video too. I must have missed it. What was used in the video that cannot be used on less than 5.1.x?

jekinney's avatar

Sometimes upgrading to a major release like 5.1 doesn't work as expected. Hate to say it, but try a fresh install. Then you can copy the code over.

mstnorris's avatar

Try composer dump-autoload -o, that could do the trick. If not, go through the videos again on a clean install and make sure you're doing everything right. If it works, well, you went wrong the first time around. It it doesn't then there could be another issue (check the Disqus thread underneath the lesson video as others' most likely would have encountered it too).

Please or to participate in this conversation.