You need to give more details and show some code man :)
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
Did you put the following in your model?
protected $casts = [ ... ];
I did exactly the same things as JeffreyWay did and I get this error.
Apparently you haven't. :)
@toniperic such a joker ;)
//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());
@Ozan are you using the latest development version of Laravel? To double check run
php artisan
5.0.28 updating now thanks ... see? I did the exact same thing :D
:/ still the same
What version are you running now?
Laravel Framework version 5.0.31
What do you want to achieve here ?
You need
"laravel/framework": "5.1.*"
Did it released?
@Ozan it is the development version, Jeffrey says so at the beginning of the video. It will be released soon.
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?
@JeffreyWay @mstnorris :D Here is a fun fact: I updated to 5.1.*@dev but it still gives the same error.
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 @jekinney That was what I did actually... But it doesn't work I really don't know what to do.
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).
@JeffreyWay posted the code to github - https://github.com/laracasts/Mass-User-Settings
Please or to participate in this conversation.