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!

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top