本文整理汇总了PHP中app\City::find方法的典型用法代码示例。如果您正苦于以下问题:PHP City::find方法的具体用法?PHP City::find怎么用?PHP City::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\City
的用法示例。
在下文中一共展示了City::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_city
public function update_city($city_id, Request $request)
{
$city = City::find($city_id);
$city->name = $request->name;
$city->save();
return redirect('cities');
}
示例2: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index(Request $request)
{
$country = Country::find($request->country_id);
$city = City::find($request->city_id);
$state = State::find($request->state_id);
return ['country' => $country->name, 'city' => $city->name, 'state' => $state->name];
}
示例3: remove
public function remove(Request $request)
{
$oCity = City::find($request->id);
$oCity->delete();
$request->session()->flash('notify', ['type' => 'Success', 'text' => 'Данные успешно удалены!']);
return redirect('city');
}
示例4: leave_feedback
public function leave_feedback($city_id, $location_id, Request $request)
{
$checkin = new Checkin($request->all());
$checkin->user_id = Auth::id();
$city = City::find($city_id);
$location = $city->locations()->find($location_id);
$location->checkins()->save($checkin);
return back();
}
示例5: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if ($this->option('all')) {
foreach (City::all() as $city) {
$city->import();
sleep(5);
}
} elseif ($this->argument('city')) {
$city = City::find($this->argument('city'));
if (count($city)) {
$city->import();
}
}
}
示例6: gmapsPost
public function gmapsPost()
{
$data = $this->request->all();
if ($data['city_id']) {
$city_id = City::getCityFromAutoComplete($data['city_id']);
$city = City::find($city_id);
$long = $city->long;
$lat = $city->lat;
} else {
$long = $data['long'];
$lat = $data['lat'];
}
isset($data['marker']) ? $marker = 1 : ($marker = 0);
return redirect()->route('gmaps.get.coords', [$lat, $long, $marker]);
}
示例7: checkin
public function checkin($city_id, $location_id, $user_id, Request $request)
{
$checkin = new Checkin($request->all());
$user = User::find($user_id);
if (!$user) {
return response()->json(['message' => ['type' => 'error', 'body' => 'There are no user with this ID']]);
}
$checkin->user_id = $user_id;
$city = City::find($city_id);
if (!$city) {
return response()->json(['message' => ['type' => 'error', 'body' => 'There are no city with this ID']]);
}
$location = $city->locations()->find($location_id);
if (!$location) {
return response()->json(['message' => ['type' => 'error', 'body' => 'There is no location with this ID']]);
}
$location->checkins()->save($checkin);
return response()->json(['message' => ['type' => 'success', 'body' => ['new_rating' => $location->checkins()->avg('rating'), 'checkin' => 'User successfuly was cheked-in']]]);
}
示例8: getTrainUnit
/**
* creates the unit training task based on the submitted POST request.
*
* @param Request $request
* @param $city_id
* @param $slot_num
* @param $building_id
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function getTrainUnit($city_id, $slot_num, $building_id, $type)
{
$city = City::find($city_id);
if (!$this->validateOwner($city)) {
return redirect('/home')->withErrors('Nem a te városod');
}
if ($building = $this->buildingCompleted($building_id)) {
// check if the building is completed
TaskController::checkTasks();
// check if there any pending tasks and complete the finished ones
if ($building->workers > 0) {
// check if there's at least one worker in the building
if ($building->type == 5) {
// check if the type of the building is 'barrack'
$lack_resource = $city->hasEnoughResources(Army::$unit_prices[$city->nation][$type]);
if (empty($lack_resource)) {
// check if the city has enough resources to train the unit
if ($city->human_resources->population > 0) {
// check if the city has enough population (i.e. at least 1)
$city->human_resources->population -= 1;
$city->human_resources->save();
// if everything is set, remove one from the population of the city and save the new population
$city->resources->subtract(Army::$unit_prices[$city->nation][$type]);
// remove the amount of resources needed by the training of the unit
TaskController::createTask($building, $type + 10, Army::$unit_times[$city->nation][$type]);
// create the task
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}");
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_population' => 'Nincs elég népesség']);
}
$messages = [];
$resources = ['stone' => 'kő', 'lumber' => 'fa', 'food' => 'élelmiszer', 'iron' => 'vas'];
foreach ($lack_resource as $key => $value) {
$messages["not_enough_{$key}"] = "Még {$value} {$resources[$key]} hiányzik";
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors($messages);
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_a_forum' => 'Az épület nem tud munkást képezni']);
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_worker' => 'Az épületben nem dolgozik munkás']);
}
return redirect("/city/{$city_id}");
}
示例9: getMakeSettler
/**
* @param $city_id
* @param $slot_num
*/
public function getMakeSettler($city_id, $slot_num, $building_id)
{
$city = City::find($city_id);
if (!$this->validateOwner($city)) {
return redirect('/home')->withErrors('Nem a te városod');
}
if ($building = $this->buildingCompleted($building_id)) {
TaskController::checkTasks();
if ($building->task->where('building_id', $building->id)->first()) {
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['already_training' => 'Az épület használatban van']);
}
if ($building->workers > 0) {
if ($building->type == 7) {
$lack_resource = $city->hasEnoughResources(HumanResource::$settler_price[$city->nation]);
if (empty($lack_resource)) {
if ($city->resources->workers >= 5) {
if ($city->resources->population >= 10) {
$city->resources->workers -= 5;
$city->resources->population -= 10;
$city->resources->save();
$city->resources->subtract(HumanResource::$settler_price[$city->nation]);
TaskController::createTask($building, 2, HumanResource::$settler_time[$city->nation]);
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}");
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_population' => 'Nincs elég népesség']);
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_worker' => 'Nincs elég munkás']);
} else {
$messages = [];
$resources = ['stone' => 'kő', 'lumber' => 'fa', 'food' => 'élelmiszer', 'iron' => 'vas'];
foreach ($lack_resource as $key => $value) {
$messages["not_enough_{$key}"] = "Még {$value} {$resources[$key]} hiányzik";
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors($messages);
}
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_a_forum' => 'Az épület nem tud telepest képezni']);
}
return redirect("/city/{$city_id}/slot/{$slot_num}/building/{$building_id}")->withErrors(['not_enough_worker' => 'Az épületben nem dolgozik munkás']);
}
return redirect("/city/{$city_id}");
}
示例10: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$this->validate($request, ['city_id' => 'integer|exists:city,id', 'tag_id' => 'integer|exists:tag,id', 'type' => 'string|in:' . implode(',', Place::types())]);
if ($request->has('city_id')) {
$city = City::find($request->input('city_id'));
} else {
$city = City::where('geoname_id', 658225)->first();
if (!count($city)) {
$city = City::first();
}
}
$query = Place::where('city_id', $city->id);
if ($request->has('search')) {
$words = explode(" ", $request->input('search'));
$query->whereHas('translations', function ($sub_query) use($words) {
foreach ($words as $word) {
// If it is Chinese, use LIKE. Else, use full text index.
// http://www.regular-expressions.info/unicode.html#script
if (preg_match('/\\p{Han}+/u', $word)) {
$sub_query->where(function ($q) use($word) {
$q->where('name', 'like', '%' . $word . '%')->orWhere('content', 'like', '%' . $word . '%');
});
} else {
$sub_query->whereRaw('MATCH(name,content) AGAINST(? IN BOOLEAN MODE)', [$word . '*']);
}
}
});
}
if ($request->has('type')) {
$query = $query->where('type', $request->input('type'));
}
if ($request->has('tag_id')) {
$query = $query->whereHas('tags', function ($sub_query) use($request) {
$sub_query->where('id', $request->input('tag_id'));
});
}
$query->with('image');
$places = $query->orderBy('like_count', 'desc')->paginate(24);
return view('pages.place.index', ['places' => $places, 'city' => $city, 'type' => $request->input('type')]);
}
示例11: search
/**
* Search
*/
public function search(Request $request)
{
$properties = Property::orderBy('created_at', 'DESC');
if ($request->get('property_type') != 0) {
$properties = $properties->where('property_type_id', $request->get('property_type'));
}
if ($request->get('property_status') != 0) {
$properties = $properties->where('property_status_id', $request->get('property_status'));
}
if ($request->get('town_id') != 0) {
$town = \App\Town::find($request->get('town_id'));
$ids = [];
foreach ($town->streets as $street) {
$ids[] = $street->id;
}
$properties = $properties->whereIn('street_id', $ids);
} elseif ($request->get('city_id') != 0) {
$city = \App\City::find($request->get('city_id'));
$ids = [];
foreach ($city->towns->streets as $street) {
$ids[] = $street->id;
}
$properties = $properties->whereIn('street_id', $ids);
}
if ($request->get("is_credit") != 0) {
$properties = $properties->where('is_credit', $request->get('is_credit') == 1 ? true : false);
}
if ($request->get("is_site") != 0) {
$properties = $properties->where('is_site', $request->get('is_site') == 1 ? true : false);
}
if ($request->get("min")) {
$properties = $properties->where('price', '>=', $request->get('min'));
}
if ($request->get('max')) {
$properties = $properties->where('price', '<=', $request->get('max'));
}
$properties = $properties->paginate(20);
return view('property.index', ['properties' => $properties, "title" => trans('search.result')]);
}
示例12: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
// Start Check Authorization
$invalid_auth = 1;
$authRole = Auth::user()->UserRoles->role;
if ($authRole == 1 or $authRole == 3) {
$invalid_auth = 0;
}
if ($invalid_auth == 1) {
Alert::error('Anda tidak memilik akses ini')->persistent('close');
return redirect('dashboard');
}
// End Check Authorization
$validation = Validator::make($request->all(), City::rules($id));
// Check if it fails //
if ($validation->fails()) {
return redirect()->back()->withInput()->with('errors', $validation->errors());
}
// Process valid data & go to success page //
$city = City::find($id);
// replace old data with new data from the submitted form //
// save city data into database //
$city->name = $request->input('name');
$city->id_provinces = $request->input('id_provinces');
$city->save();
Alert::success($request->input('name') . ' Saved!')->persistent("Close");
return redirect('city/list')->with('message', 'You just updated an cateogry!');
}
示例13: redirect
return redirect(url('/admin'))->withInput()->withErrors($validator);
}
$user = Property::find($data['property_id'])->delete();
return redirect(url('/admin'));
});
Route::delete('/property/photo/{picture}', function (Picture $picture) {
\Cloudinary\Uploader::destroy($picture->cloudinary_public_id);
$property_id = PropertyPictureBridge::where('picture_id', $picture->id)->get()[0]->property_id;
$picture->delete();
return redirect(url('/property/edit/photos/' . $property_id));
});
Route::get('/property/edit/{property_id}', function ($property_id) {
$cities = City::orderBy('name', 'asc')->get();
$property = Property::find($property_id);
$property->district_name = District::find($property->district_id)->name;
$property->city_name = City::find($property->city_id)->name;
$amenities = PropertyFeatures::where('property_id', $property->id)->get()[0];
return view('edit_property', ['property' => $property, 'cities' => $cities, 'amenities' => $amenities]);
});
Route::get('/property/edit/photos/{property_id}', function ($property_id) {
$property = Property::find($property_id);
$images = get_all_images_from_property_id_without_placeholder($property_id);
return view('edit_images', ['property' => $property, 'images' => $images]);
});
Route::post('/property/edit', function (Request $request) {
$data = $request->all();
$validator = Validator::make($request->all(), ['title' => 'required|max:255', 'city' => 'required', 'district' => 'required', 'address' => 'required|max:255', 'type' => 'required|in:private_room,shared_room,entire_place', 'max_occupancy' => 'required|numeric|min:0|integer', 'price_per_night' => 'required|numeric|min:0|max:9999.99', 'description' => 'required', 'property_id' => 'required|numeric|integer|min:0']);
if ($validator->fails()) {
return redirect(url('/property/edit/' . $data['property_id']))->withInput()->withErrors($validator);
}
$myErrorArr = array();
示例14: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, Request $request)
{
$city = City::find($id);
$city->update($request->all());
return redirect('admin/cities');
}
示例15: getArmyData
public function getArmyData(Request $request)
{
TaskController::checkTasks();
$army = Army::where('id', $request->input('army_id'))->first()->toArray();
$hex = Grid::find($army['current_hex_id']);
// if there's a city on the current hex
if ($hex->city > 0) {
$city = City::find($hex->city);
$army['city_nation'] = intval($city->nation);
$army['city_name'] = $city->name;
}
$army['hex_type'] = $hex->type;
$army['hex_owner'] = User::find($hex->owner)->name;
if (Auth::user()->id === $army['user_id']) {
return $army;
} else {
$units = ['unit1' => 0, 'unit2' => 0, 'unit3' => 0, 'unit4' => 0, 'unit5' => 0, 'unit6' => 0, 'unit7' => 0];
$army = array_diff_key($army, $units);
$user = User::find($army['user_id']);
$army['army_owner'] = $user->name;
$army['nation'] = intval($user->nation);
return $army;
}
}