Laravel - Controller在Localhost中工作,不适用于Production

时间:2016-07-18 21:20:44

标签: php mysql laravel laravel-5 laravel-5.2

我有一个像这样的Laravel控制器 -

public function detailedMapItem()
{
    $requestData = Request::all();
    //Update View Count - Not Working
    /*UserAdvertisementView::firstOrCreate([
                                    'user_id'   =>  Auth::user()->id,
                                    'add_id'    =>  $requestData['product_id']
                                ])->increment('total_view');*/
    //So do it with Query Bilder
    $user_id = 1;   //Default User ID for non logged in users
    if(Auth::check())
        $user_id = Auth::user()->id;
    $prev_element = DB::table('user_add_views')
                ->where('user_id', $user_id)
                ->where('add_id', $requestData['product_id']);
    if($prev_element->count()>0)
    {
        $prev_element=$prev_element->pluck('total_view');
        DB::table('user_add_views')
                ->where('user_id', $user_id)
                ->where('add_id', $requestData['product_id'])
                ->update([
                            'total_view' => $prev_element[0]+1
                        ]);
    }
    else
    {
        DB::table('user_add_views')->insert([
                                        'user_id'   =>  $user_id,
                                        'add_id'    =>  $requestData['product_id']
                                    ]);
    }
    //Return the Product detail
    $advertisement = Advertisement::with('AdvertisementImages')
                        ->find($requestData['product_id']);

    $add_owner  =   DB::table('users')
                        ->join('user_reviews', 'users.id', '=', 'user_reviews.add_owner_id')
                        ->select(
                                'users.id as user_id',
                                DB::raw("
                                            CASE WHEN users.profile_picture IS NULL or users.profile_picture = ''
                                                THEN
                                                    '".url('images/empty-profile.jpg')."'
                                                ELSE
                                                    CONCAT('".url('uploads')."','/', users.profile_picture)
                                                END
                                            as profile_picture"
                                        ),
                                DB::raw("CONCAT(users.first_name, ' ', users.last_name) AS user_name"),
                                'users.cell_no as cell_no',
                                'users.website as website',
                                'users.email as email',
                                DB::raw("FLOOR( AVG(user_reviews.rating) ) AS user_rating")
                            )
                        ->where('id', $advertisement->user_id)
                        ->first();

    $reviews = DB::table('user_reviews')
                    ->join('users', 'users.id', '=', 'user_reviews.user_id')
                    ->select(
                                DB::raw("CONCAT(users.first_name, ' ', users.last_name) AS user_name"),
                                'user_reviews.review as review',
                                'user_reviews.rating as rating',
                                DB::raw("DATE_FORMAT(user_reviews.updated_at,'%D %b %Y, %r') AS added_on")
                            )
                    ->where('add_id', $requestData['product_id'])
                    ->orderBy('user_reviews.updated_at', 'desc')
                    ->get();

    return [
                'advertisement' =>  $advertisement,
                'reviews'       =>  $reviews,
                'add_owner'     =>  $add_owner
            ];
}

localhost 正常工作

但问题是,我没有从生产中获得完美的数据。

在生产中找到

'advertisement' => $advertisement数据。

'add_owner' => $add_owner被视为NULL

我可以保证这不是 MySQL DB 的问题。

可以有任何理由吗?

提前感谢您的帮助。

0 个答案:

没有答案