こんにちは:Laravel 5.2未定義のインデックス:私はこのexecptionを持っている理由緯度
これはコントローラです:
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();
}
}
これはモデルです:
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);
}
}
私はすべてを試してみてください作者のdump-autoload、php artisan migrate:rollbackを覚えていて、再びm igrationなど私はDBの緯度と経度のフィールドがあります。ありがとう。
これを見ると、 'latitude'が' $ inputs'配列にないからです。 –