Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我可以使用雄辩的访问者&;DB facade上的变异体?如果没有,那么还有其他选择吗?_Php_Mysql_Laravel 5.2 - Fatal编程技术网

Php 我可以使用雄辩的访问者&;DB facade上的变异体?如果没有,那么还有其他选择吗?

Php 我可以使用雄辩的访问者&;DB facade上的变异体?如果没有,那么还有其他选择吗?,php,mysql,laravel-5.2,Php,Mysql,Laravel 5.2,为了查询表,我使用了DB facade。我想在返回结果之前操作列值。 我在modal中使用了雄辩的访问器getAttribute()方法,但它什么也不做 现在我想要的是在json结果中,您可以看到我需要操作的operating_hour列,作为交换,我只想替换一些字符,比如~or: 注意:问题是我只想使用json.parse()解析这些json结果,但它会抛出一些错误。我只是想可能是因为我无法解析这些字符,这就是为什么我想使用Accessor,但它对我没有帮助。您可以尝试解析该json结果。需要

为了查询表,我使用了DB facade。我想在返回结果之前操作列值。 我在modal中使用了雄辩的访问器getAttribute()方法,但它什么也不做

现在我想要的是在json结果中,您可以看到我需要操作的operating_hour列,作为交换,我只想替换一些字符,比如~or:


注意:问题是我只想使用json.parse()解析这些json结果,但它会抛出一些错误。我只是想可能是因为我无法解析这些字符,这就是为什么我想使用Accessor,但它对我没有帮助。您可以尝试解析该json结果。需要帮助。

请显示DB调用的代码以及模型的代码。您在控制器中提供的方法还是模型中提供的方法?方法位于模态“餐厅”中,并从控制器调用。在这种情况下,您是否也可以显示控制器方法的代码???
    public function findRestaurantByCordinates($request)
    {
        $numPerPage = 6;
        $page = ($request->input('page')) ? $request->input('page') : 1;

            $sql = "r.*,  ( 6371 * acos( cos( radians(".$request->input('lat').") ) * cos( radians( res_lat ) ) * cos( radians( res_lon ) - radians(".$request->input('lang').") ) + sin( radians(".$request->input('lat').") ) * sin( radians( res_lat ) ) ) ) AS distance";


            /*custom query for results*/
            $result = DB::table('restaurants as r');

        if($request->input('lat') && $request->input('lang'))
        {
            $result = $result->select(DB::raw($sql));
            $result = $result->having('distance', '<', 20);
        }

        if(!empty($request->input('features')))
        {
            $result = $result->join('res_features', 'r.restaurant_id', '=', 'res_features.restaurant_id');
        }

        if(!empty($request->input('tags')))
        {
            $result = $result->join('res_tags', 'r.restaurant_id', '=', 'res_tags.restaurant_id');
        }

        if(!empty($request->input('features')))
        {
            $result = $result->whereIn('res_features.feature_id', $request->input('features'));
        }

        if(!empty($request->input('tags')))
        {
            $result = $result->whereIn('res_tags.tag_id', $request->input('tags'));
        }

        $result = $result
                    ->groupBy('r.restaurant_id')
                    ->get();

        // Start displaying items from this number;
        $offSet = ($page * $numPerPage) - $numPerPage; // Start displaying items from this number
       //dd($offSet);

        // Get only the items you need using array_slice (only get 10 items since that's what you need)
        $itemsForCurrentPage = array_slice($result, $offSet, $numPerPage, true);

        //dd($itemsForCurrentPage);

        $pagination = new LengthAwarePaginator($itemsForCurrentPage, count($result), $numPerPage, $page, ['path' => $request->url(), 'query' => $request->query()]);


        return $pagination;
    }
   [{"restaurant_id":63,"res_title":"Foruche ","res_title_jp":"フォルチェ","city_id":0,"pre_id":22,"res_address":"1-5-2 Dogenzaka Shibuya Tokyo","res_address_jp":"東京都 渋谷区 道玄坂 1-5-2 渋谷SEDEビル 5F","res_lat":"35.6580514","res_lon":"139.6973349","res_overview":"","res_overview_jp":"","res_phone_1":"050-5868-2467 (+81-50-5868-2467) ","res_phone_2":"03-3476-7776 (+81-3-3476-7776) ","res_fax":"","res_email":"","res_website":"","lunch_start_price":0,"lunch_end_price":0,"dinner_start_price":0,"dinner_end_price":0,"occupancy":"","operating_hour":"17:30~翌2:00         15:00~23:00","res_status":"","created_by":0,"updated_by":0,"created_at":"0000-00-00 00:00:00","updated_at":"0000-00-00 00:00:00","slug":"test","distance":6.4750019625656},{"restaurant_id":65,"res_title":"Bishokumaimon ","res_title_jp":"美食 米門 渋谷店","city_id":0,"pre_id":22,"res_address":"Tokyo, Shibuya-ku, Udagawa-cho, 15-1 Shibuya Parco PART1 8F","res_address_jp":"東京都 渋谷区 宇田川町 15-1 渋谷パルコ PART1 8F","res_lat":"35.6619563","res_lon":"139.6967115","res_overview":"","res_overview_jp":"","res_phone_1":"050-5869-7460 (+81-50-5869-7460)","res_phone_2":"03-4577-6648 (+81-3-4577-6648)","res_fax":"","res_email":"","res_website":"","lunch_start_price":0,"lunch_end_price":0,"dinner_start_price":0,"dinner_end_price":0,"occupancy":"","operating_hour":" 11:00 ~ 15:00        17:30 ~ 23:30","res_status":"","created_by":0,"updated_by":0,"created_at":"0000-00-00 00:00:00","updated_at":"0000-00-00 00:00:00","slug":"test","distance":6.1275693867962},{"restaurant_id":67,"res_title":"GANEZA ","res_title_jp":"ガネーシャ 日本橋浜町店","city_id":907,"pre_id":41,"res_address":"2-30-6 Nihonbashihamacho Chuo Tokyo","res_address_jp":"東京都 中央区 日本橋浜町 2-30-6 花の東京ビル 1F","res_lat":"35.6873505","res_lon":"139.7854157","res_overview":"","res_overview_jp":"","res_phone_1":"","res_phone_2":"+81-3-5623-5460","res_fax":"","res_email":"","res_website":"","lunch_start_price":999,"lunch_end_price":0,"dinner_start_price":1000,"dinner_end_price":1999,"occupancy":"38 seats","operating_hour":"(ランチ)11:00~15:00
    (ディナー)16:00~22:00
    Lunch","res_status":"A","created_by":0,"updated_by":0,"created_at":"0000-00-00 00:00:00","updated_at":"2016-07-03 23:16:19","slug":"test","distance":5.3927689064301},{"restaurant_id":68,"res_title":"Nihonkaishouya ","res_title_jp":"日本海庄や 町屋店","city_id":0,"pre_id":22,"res_address":"6-6-1 Arakawa Arakawa Tokyo","res_address_jp":"東京都 荒川区 荒川 6-6-1","res_lat":"35.7427213","res_lon":"139.777968","res_overview":"","res_overview_jp":"","res_phone_1":"050-5571-0368 (+81-50-5571-0368) ","res_phone_2":"03-5901-4631 (+81-3-5901-4631) ","res_fax":"","res_email":"","res_website":"","lunch_start_price":0,"lunch_end_price":0,"dinner_start_price":0,"dinner_end_price":0,"occupancy":"","operating_hour":"11:30~23:30","res_status":"","created_by":0,"updated_by":0,"created_at":"0000-00-00 00:00:00","updated_at":"0000-00-00 00:00:00","slug":"test","distance":5.5912895038939},{"restaurant_id":77,"res_title":"Jitokkokumiai ","res_title_jp":"じとっこ組合 世田谷経堂店","city_id":0,"pre_id":22,"res_address":"1-25-17 Kyodo Setagaya Tokyo","res_address_jp":"1-25-17 Kyodo Setagaya Tokyo","res_lat":"35.6490287","res_lon":"139.6340795","res_overview":"","res_overview_jp":"","res_phone_1":"050-5868-3517 (+81-50-5868-3517)","res_phone_2":"03-6413-1940 (+81-3-6413-1940)","res_fax":"","res_email":"","res_website":"","lunch_start_price":0,"lunch_end_price":0,"dinner_start_price":0,"dinner_end_price":0,"occupancy":"","operating_hour":"17:00~1:00             17:00~24:00","res_status":"","created_by":0,"updated_by":0,"created_at":"0000-00-00 00:00:00","updated_at":"0000-00-00 00:00:00","slug":"test","distance":11.07793356266},{"restaurant_id":92,"res_title":"Kagoshimakenkirishimashitsukadanoujou ","res_title_jp":"鹿児島県霧島市 塚田農場 中目黒店","city_id":0,"pre_id":22,"res_address":"1-20-5 Kamimeguro Meguro Tokyo","res_address_jp":"東京都 目黒区 上目黒 1-20-5 エーワンビル","res_lat":"35.6446883","res_lon":"139.696901","res_overview":"","res_overview_jp":"","res_phone_1":"050-5570-7183 (+81-50-5570-7183)","res_phone_2":"050-5570-7183 (+81-50-5570-7183)","res_fax":"","res_email":"","res_website":"","lunch_start_price":0,"lunch_end_price":0,"dinner_start_price":0,"dinner_end_price":0,"occupancy":"","operating_hour":"17:00~24:00","res_status":"","created_by":0,"updated_by":0,"created_at":"0000-00-00 00:00:00","updated_at":"0000-00-00 00:00:00","slug":"test","distance":7.8247499035529}]