Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

Can you put some code please maybethat can help us to help you ;) but maybe the problem could be in the model

Last updated 1 year ago.
0

The Profile.php:

<?php use Illuminate\Auth\UserTrait; use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableTrait; use Illuminate\Auth\Reminders\RemindableInterface; class Profile extends Eloquent implements UserInterface, RemindableInterface { use UserTrait, RemindableTrait, SoftDeletingTrait; /** * The database table used by the model. * * @var string */ protected $table = 'profiles'; protected $dates = ['deleted_at']; /** * The attributes excluded from the model's JSON form. * * @var array */ public function profile() { return $this->belongsTo('User'); } public function like() { return $this->hasMany('Like'); } public function post() { return $this->hasMany('Post'); } public function servePosts() { return Post::where('user_id', '=', $this->id)->orderBy('id', 'desc')->paginate(12); } } Post.php: <?php use Illuminate\Auth\UserTrait; use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableTrait; use Illuminate\Auth\Reminders\RemindableInterface; class Post extends Eloquent implements UserInterface, RemindableInterface { use UserTrait, RemindableTrait, SoftDeletingTrait; /** * The database table used by the model. * * @var string */ protected $table = 'posts'; protected $dates = ['deleted_at']; /** * The attributes excluded from the model's JSON form. * * @var array */ public function user() { return $this->belongsTo('Profile'); } public function categories() { return $this->hasMany('Category'); } public function likes() { return $this->hasMany('Like'); } public function serveLikes() { $likes = Like::where('post_id', '=', $this->id)->where('type', '=', 'blog')->count(); $comments = Comment::where('post_id', '=', $this->id)->count(); return $likes + $comments; } public function serveComments() { //return Comment::wherePost_id($this->id)->get(); } public function postImage() { return Media::find($this->postimage_id)['image_link'] ; } } And that's it.
Last updated 1 year ago.
0

Guys, I found the problem... And I'm sorry. It wasn't an issue with the code (although there are issues and I'm working on it) but with the database. My bad!

So here's a cat running in a tumbler which I think is apt for the life of a programmer. cat in dryer

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

RoffeDH roffedh Joined 7 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.