من برای گالریم لایک قراردادم
اسم مدلم gallery که طبیعتا اسم جدولش میشه galleries
یه مدل دارم با نام Like و جدولش likes
$table->bigIncrements('id');
$table->integer('gallery_id');
$table->integer('user_id')->default(0);
$table->boolean('like');
$table->timestamps();
با متد sync میخواستم لایک اضافه کنم
$gallery = Gallery::find($request->gallery_id);
$gallery->likes()->sync($request->all());
وقتی میخوام برای درج لایک تو دیتابیس از sync استفاده کنم ارور میده
Base table or view not found: 1146 Table 'test.gallery_like' doesn't exist (SQL: select * from gallery_like where gallery_id = 9)"
شاید پاسخ شما همینجا باشد
دوست عزیز شاید این لینک کمک تون بکنه.
سیستم لایک در لارول و گیت هاب : https://github.com/mydnic/Laravel-Like-System-Example
درود
بنده پکیجی نوشتم که با بهره گیری از Polymorphism میشه قابلیت Like کردن رو ، به هر مدل الکوئنت که خواستید اضافه کنید.
مراحل نصب و استفاده از پکیج در ریپازیتوری گیت هاب موجوده:
https://github.com/AliBayat/Laravel-Likeable
با استفاده از این پکیج به عملکرد های زیر دسترسی خواهید داشت:
بطور مثال برای مدل Post:
$post->like(); // like the post for current user
$post->like($userId); // pass in the user id
$post->like(0); // just adding likes to the count, and don't track any user
$post->unlike(); // remove like from the post
$post->unlike($userId); // pass in the user id
$post->unlike(0); // remove likes from the count -- does not check for user
$post->likeCount; // get Total count of likes
$post->likes; // Collection (Illuminate\Database\Eloquent\Collection) of existing likes
$post->liked(); // check if currently logged in user liked the post
$post->liked($userId); // pass in the user id
Post::likedBy($userId) // find only posts where user liked them
->with('likeCounter') // with eager loading
->get();
تنها کافیه از Trait پکیج در مدل موردنظر استفاده کنید.