本文整理汇总了PHP中app\Location::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Location::find方法的具体用法?PHP Location::find怎么用?PHP Location::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Location
的用法示例。
在下文中一共展示了Location::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareQuery
/**
* @return ElasticaQuery
*/
private function prepareQuery($params, $start = null, $limit = null)
{
$query = null;
$filter = null;
$sort = ['_score' => 'desc'];
// We'd like to search in both title and description for keywords
if (!empty($params['keywords'])) {
$query = new QueryString($params['keywords']);
$query->setDefaultOperator('AND')->setFields(['title', 'description']);
}
// Add location filter is location is selected from autosuggest
if (!empty($params['location_id'])) {
$location = Location::find($params['location_id']);
$filter = new GeoDistance('location', ['lat' => $location->lat, 'lon' => $location->lon], $params['radius'] . 'mi');
// Sort by nearest hit
$sort = ['_geo_distance' => ['jobs.location' => [(double) $location->lon, (double) $location->lat], 'order' => 'asc', 'unit' => 'mi']];
}
// If neither keyword nor location supplied, then return all
if (empty($params['keywords']) && empty($params['location_id'])) {
$query = new MatchAll();
}
// We need a filtered query
$elasticaQuery = new ElasticaQuery(new Filtered($query, $filter));
$elasticaQuery->addSort($sort);
// Offset and limits
if (!is_null($start) && !is_null($limit)) {
$elasticaQuery->setFrom($start)->setSize($limit);
}
// Set up the highlight
$elasticaQuery->setHighlight(['order' => 'score', 'fields' => ['title' => ['fragment_size' => 100], 'description' => ['fragment_size' => 200]]]);
return $elasticaQuery;
}
示例2: boot
public static function boot()
{
parent::boot();
static::creating(function ($model) {
if ($model->status == null) {
$model->status = static::CREATE;
}
if ($model->qty == null) {
$model->qty = 1;
}
if ($model->location_id != null) {
$location = Location::find($model->location_id, ['name']);
if ($location) {
$model->location_name = $location->name;
}
}
});
static::created(function ($model) {
});
static::updating(function ($model) {
if ($model->qty == null) {
$model->qty = 1;
}
});
}
示例3: saveReferees
public function saveReferees(Season $season, Competition $competition, Request $request)
{
$data = $request->all();
$competition->referees()->wherePivot('season_id', '=', $season->id)->detach();
$pairs = $this->getPairs($season, $competition);
foreach ($pairs as $pair) {
$pair->active = 0;
$pair->save();
}
$response = ['refs' => array(), 'crefs' => array()];
$country = Country::find($data['country']);
$refs = json_decode($data['referees'], true);
foreach ($refs as $ref) {
$newRef = $competition->storeReferee($ref, $season, 0, $country);
if (array_key_exists('styled', $ref)) {
if ($ref['styled'] == 'new') {
$newRef['location'] = Location::find($newRef->location_id)->name;
array_push($response['refs'], $newRef);
}
}
}
$crefs = json_decode($data['court_referees'], true);
foreach ($crefs as $cref) {
$newRef = $competition->storeReferee($cref, $season, 1, $country);
if (array_key_exists('styled', $cref)) {
if ($cref['styled'] == 'new') {
$newRef['location'] = Location::find($newRef->location_id)->name;
array_push($response['crefs'], $newRef);
}
}
}
$response['pairs'] = $this->getPairs($season, $competition)->toArray();
return $response;
}
示例4: deleteLocation
/**
* Delete employee location from DB
*
* @param $id
* @return mixed
*/
public function deleteLocation($id)
{
$location = Location::find($id);
if (count($location->employees()->get()->toArray())) {
return redirect()->back()->with('danger_flash_message', 'You cannot delete a location that is in use.');
}
$location->delete();
return redirect()->route('manageLocations')->with('flash_message', 'Location ' . $location->name . ' has been deleted');
}
示例5: getLocationNameByCode
public function getLocationNameByCode(Request $request, $code)
{
$location = Location::find($code);
if ($location == null) {
return response()->json(['name' => ""]);
}
$name = $location->name;
return ['name' => $name];
}
示例6: destroy
public function destroy($id)
{
$location = Location::find($id);
if ($location->delete()) {
return $this->output('Location deleted');
} else {
return $this->notFound('Location not found');
}
}
示例7: postDeleteLocation
public function postDeleteLocation(Request $request)
{
$locationId = intval($request->input('location_id'));
if ($locationId) {
Location::find($locationId)->delete();
return response(Location::all());
}
return redirect('dashboard/locations')->withErrors('No location id passed');
}
示例8: countComments
public static function countComments($id)
{
$comments = \App\Comment::where('id_location', '=', $id);
$location = Location::find($id);
$location->rating = ceil($comments->avg('rating') / 0.5) * 0.5;
$location->voters = $comments->count();
$location->save();
return $avgRating;
}
示例9: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $location_id, $id)
{
$location = Location::find($location_id);
$price = Price::find($id);
$price->type = $request->type;
$price->price = $request->price;
$price->price_date = $request->price_date;
$price->location()->associate($location);
$price->save();
return redirect()->action('LocationController@show', $price->location->id);
}
示例10: fromLocationWithCoordinates
public static function fromLocationWithCoordinates($location_id, $coordinates)
{
// DOES NOT SAVE TARGET -
// must save through experiment for foreign key check
$location = Location::find($location_id);
$target = new Target();
$target->location()->associate($location);
$target->coordinates = $coordinates;
$target->is_decoy = false;
return $target;
}
示例11: tournaments
/**
* Downlod Tournaments
*
* @return Response
*/
public function tournaments(Request $request)
{
$time_period = $request->input('time_period');
$location_id = $request->input('location_id');
$location = Location::find($location_id)->location;
$ss = new Scraper();
$new_tournaments = $ss->get_tournaments($location, $time_period);
$tournaments = \DB::table('tournaments')->orderBy('start_date', 'desc')->get();
//return view('pages/tournaments', compact('tournaments'));
return redirect('admin/scraper')->with('success', 'tournaments downloaded successfully');
}
示例12: update
public function update($city, $id)
{
$location = Location::find($id);
$location->name = Request::input('name');
$location->type = Request::input('type');
$location->time = Request::input('time');
$location->specification = Request::input('specification');
$location->description = Request::input('description');
$location->price = Request::input('price');
$location->address = Request::input('address');
$location->save();
return $location;
}
示例13: findOrThrowException
/**
* @param $id
* @param bool $withUsers
* @return mixed
* @throws GeneralException
*/
public function findOrThrowException($id, $hasPcode = false)
{
if (empty($id)) {
throw new GeneralException("Location id is empty.");
}
if ($hasPcode) {
$location = Location::has('pcode')->find($id);
} else {
$location = Location::find($id);
}
if (!is_null($location)) {
return $location;
}
throw new GeneralException("That location with id {$id} does not exist.");
}
示例14: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('adjacent_location')->delete();
DB::table('locations')->delete();
$locations = [["id" => 1, "name" => "Inn", "description" => "An establishment or building providing lodging and, usually, food and drink for travelers (Starting location)", "image" => "locations/Inn-800px.png", "image_sm" => "locations/Inn-300px.png"], ["id" => 2, "name" => "Town Hall", "description" => "Public forum or meeting in which those attending gather to discuss civic or political issues, hear and ask questions about the ideas of a candidate for public office", "image" => "locations/Townhall-800px.png", "image_sm" => "locations/Townhall-300px.png"], ["id" => 3, "name" => "Smithy", "description" => "A blacksmith's shop. A place to purchase weaponry and armor or train one's skill as a blacksmith", "image" => "locations/Blacksmith-800px.png", "image_sm" => "locations/Blacksmith-300px.png"], ["id" => 4, "name" => "Military academy fortress", "description" => "An institute where soldiers and mercenaries train they martial skills", "image" => "locations/Fortress-800px.png", "image_sm" => "locations/Fortress-300px.png"]];
foreach ($locations as $location) {
Location::create($location);
}
$adjacent_locations = [["location_id" => 1, "adjacent_location_id" => 2, "direction" => "north"], ["location_id" => 1, "adjacent_location_id" => 3, "direction" => "east"], ["location_id" => 1, "adjacent_location_id" => 4, "direction" => "south"]];
foreach ($adjacent_locations as $record) {
/** @var $location Location */
$location = Location::find($record['location_id']);
/** @var $adjacent_location Location */
$adjacent_location = Location::find($record['adjacent_location_id']);
$location->addAdjacentLocation($adjacent_location, $record['direction']);
}
}
示例15: update
public function update(Request $request, $locationID)
{
if (!Auth::check() || !Auth::user()->is_admin) {
return response(view('errors.403', ['error' => $this->errorMessages['incorrect_permissions']]), 403);
}
$data = $request->only(['name', 'latitude', 'longitude', 'capacity', 'featured_image']);
// Validate all input
$validator = Validator::make($data, ['name' => 'required', 'latitude' => 'required|numeric|between:-85.05,85.05', 'longitude' => 'required|numeric|between:-180,180', 'capacity' => 'required', 'featured_image' => 'image|sometimes']);
if ($validator->fails()) {
// If validation fails, redirect back to
// registration form with errors
return Redirect::back()->withErrors($validator)->withInput();
}
if ($request->hasFile('featured_image')) {
$data['featured_image'] = MediaController::uploadImage($request->file('featured_image'), time(), $directory = "news_images", $bestFit = true, $fitDimensions = [1920, 1080]);
} else {
unset($data['featured_image']);
}
$location = Location::find($locationID);
$location->update($data);
return Redirect::route('locations.edit', [$location->id]);
}