Question

I just have a quick question. A few weeks ago I build a small app where users were able to like a post just for training. This was stored in a favorites table.

Today I wanted to implement that into an application but it does not work anymore.

I am getting this error:

Call to undefined method Illuminate\Database\Query\Builder::favorites()

I dont understand this error because I have simply copied the code from the working project. This is my route.

Route::post('favorites', ['as' => 'favorites.store', function()
{
Auth::user()->favorites()->attach(Input::get('post-id'));

return Redirect::back();
}]);

Can somebody help? Does this have anything to do with Laravel 4.1??? Would be much appreciated.

Thanks!

Était-ce utile?

La solution

Does the user model have an hasMany('favorites')? Its required to navigate from a user to his favorites.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top