douxingti9307 2017-03-13 22:33
浏览 29
已采纳

Laravel 5.2未定义索引:纬度

Hello why I have this execption:

enter image description here

This is controller:

public function addnew(Request $request)
{ 

    $data =  \Input::except(array('_token')) ;

    $rule=array(
            'restaurant_type' => 'required',
            'restaurant_name' => 'required',
            'restaurant_address' => 'required',
            'restaurant_logo' => 'mimes:jpg,jpeg,gif,png'                
             );

     $validator = \Validator::make($data,$rule);

    if ($validator->fails())
    {
            return redirect()->back()->withErrors($validator->messages());
    }
    $inputs = $request->all();

    if(!empty($inputs['id'])){

        $restaurant_obj = Restaurants::findOrFail($inputs['id']);

    }else{

        $restaurant_obj = new Restaurants;

    }


    //Slug

    if($inputs['restaurant_slug']=="")
    {
        $restaurant_slug = str_slug($inputs['restaurant_name'], "-");
    }
    else
    {
        $restaurant_slug =str_slug($inputs['restaurant_slug'], "-"); 
    }

    //Logo image
    $restaurant_logo = $request->file('restaurant_logo');

    if($restaurant_logo){

         \File::delete(public_path() .'/upload/restaurants/'.$restaurant_obj->restaurant_logo.'-b.jpg');
        \File::delete(public_path() .'/upload/restaurants/'.$restaurant_obj->restaurant_logo.'-s.jpg');

        $tmpFilePath = 'upload/restaurants/';          

        $hardPath = substr($restaurant_slug,0,100).'_'.time();

        $img = Image::make($restaurant_logo);

        $img->fit(120, 120)->save($tmpFilePath.$hardPath.'-b.jpg');
        $img->fit(98, 98)->save($tmpFilePath.$hardPath. '-s.jpg');

        $restaurant_obj->restaurant_logo = $hardPath;

    }

    $user_id=Auth::User()->id;

    $restaurant_obj->user_id = $user_id;
    $restaurant_obj->restaurant_type = $inputs['restaurant_type'];
    $restaurant_obj->restaurant_name = $inputs['restaurant_name']; 
    $restaurant_obj->restaurant_slug = $restaurant_slug;
    $address = $restaurant_obj->restaurant_address = $inputs['restaurant_address'];
    $restaurant_obj->restaurant_description = $inputs['restaurant_description'];

    //ne radi??
    $getGeoCode = Geocode::make()->address($address);

    if($getGeoCode){

        $latitude = $getGeoCode->latitude();
        $longitude = $getGeoCode->longitude();

        $restaurant_obj->latitude = $inputs['latitude'];
        $restaurant_obj->longitude = $inputs['longitude'];

    }

    $restaurant_obj->open_monday = $inputs['open_monday'];
    $restaurant_obj->open_tuesday = $inputs['open_tuesday'];
    $restaurant_obj->open_wednesday = $inputs['open_wednesday'];
    $restaurant_obj->open_thursday = $inputs['open_thursday'];
    $restaurant_obj->open_friday = $inputs['open_friday'];
    $restaurant_obj->open_saturday = $inputs['open_saturday'];
    $restaurant_obj->open_sunday = $inputs['open_sunday']; 



    $restaurant_obj->save();

    if(!empty($inputs['id'])){

        \Session::flash('flash_message', 'Changes Saved');

        return \Redirect::back();
    }else{

        \Session::flash('flash_message', 'Added');

        return \Redirect::back();

    }            


}    

This is model:

    class Restaurants extends Model
{
    protected $table = 'restaurants';

    protected $fillable = ['type', 'restaurant_name','restaurant_slug','restaurant_description','restaurant_address','delivery_charge','restaurant_logo', 'latitude', 'longitude'];


    public $timestamps = false;

    public function restaurants()
    {
        return $this->hasMany('App\Restaurants', 'id');
    }

    public static function getRestaurantsInfo($id) 
    { 
        return Restaurants::find($id);
    }

    public static function getUserRestaurant($id) 
    { 
        return Restaurants::where('user_id',$id)->count(); 
    }


    public static function getMenuCategories($id) 
    { 
        return Categories::where('restaurant_id',$id)->count(); 
    }

    public static function getMenuItems($id) 
    { 
        return Menu::where('restaurant_id',$id)->count(); 
    }

    public static function getOrders($id) 
    { 
        return Order::where('restaurant_id',$id)->count(); 
    }

    public static function getTotalRestaurants() 
    { 
        return Restaurants::count(); 
    } 


    public function scopeSearchByKeyword($query, $keyword)
    {
        if ($keyword!='') {
            $query->where(function ($query) use ($keyword) {
                $query->where("restaurant_address", "LIKE","%$keyword%")
                    ->orWhere("restaurant_name", "LIKE", "%$keyword%");                     
            });
        }
        return $query;
    }

    public static function getRestaurantOwnerInfo() 
    { 
        $rest=Restaurants::find($id);

        return User::find($rest->user_id);
    }

}

I try everything that can remember composer dump-autoload, php artisan migrate:rollback, and again make migration etc. I have fields in my db latitude and longitude. Thanks.

  • 写回答

2条回答 默认 最新

  • drm30963 2017-03-13 23:20
    关注

    It seems you're wanting to do the following by the code you posted:

    if($getGeoCode){
    
        $restaurant_obj->latitude = $getGeoCode->latitude();
        $restaurant_obj->longitude = $getGeoCode->longitude();
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析