I have a logic in my controller that works fine on the localhost but returns 'Trying to get property of non-object' on the production server.
One of the query line returns 'null', but on localhost there seems to be no problem. I'm using the same sql dumps on localhost and production in this case.
This is my Welcome Controller
class WelcomeController extends Controller
{
public function index(){
$blog_posts = DB::connection('mysql_wp')->table('wp_posts')->where('post_type', 'post')->where('post_status', 'publish')->orderBy('post_date', 'DESC')->take(3)->get();
foreach($blog_posts as $key => $blog_post){
$post = DB::connection('mysql_wp')->table('wp_posts')->where('post_type', 'attachment')->where('post_status', 'inherit')->where('post_parent', $blog_post->ID)->orderBy('post_date', 'DESC')->first();
//some more logic
}
return view('welcome', ['blog_posts' => $blog_posts]);
}
}
So here I'm getting $post as null which my further logic relies on. Unable to figure out whats the problem.
I'm using a Linux EC2 instance for prod. Help appreciated. TIA.
@Anand Naik B, can you ssh into your ec2 instance and try PHP artisan tinker to see if the $blog_post->ID
contains a reference to the calling table. I think this is one of the quickest ways for you to check it out on production.
I think its array object related issues. Can you show us the dd($blog_posts)
results ?
$blog_post[0]->ID
or
$blog_post['ID']