本文整理汇总了PHP中app\Location::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Location::findOrFail方法的具体用法?PHP Location::findOrFail怎么用?PHP Location::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Location
的用法示例。
在下文中一共展示了Location::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$location = Location::findOrFail(Input::get('id'));
$location->name = Input::get('name');
$location->save();
return Response::json(array('success' => 'Location has been updated!'));
}
示例2: 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)
{
$location = Location::findOrFail($id);
$location->update($request->all());
Session::flash('message', "Location {$id} Updated");
return redirect()->action('LocationsController@index');
}
示例3: update
public function update(LocationRequest $request, $id)
{
$location = \App\Location::findOrFail($id);
$location->update($request->all());
\Session::flash('flash_message', 'Location has been updated.');
return redirect('locations');
}
示例4: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(LocationRequest $request, $id)
{
$location = Location::findOrFail($id);
$location->fill($request->all());
$location->save();
return Redirect::back()->with("good", "Successfully updated location.");
}
示例5: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$location = Location::findOrFail($id);
$weathers = Weather::get($location->name);
$hospitals = Hospital::where('address', 'LIKE', "%{$location->name}%")->get();
$request = ['weathers' => $weathers, 'hospitals' => $hospitals];
return json_encode($request);
}
示例6: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$location = Location::findOrFail($id);
$this->validate($request, ['location' => 'required|max:100']);
$location->location = $request->location;
$location->update();
Session::flash('flash_message', 'Location successfully updated!');
return redirect()->route("location.index");
}
示例7: getStatistics
public function getStatistics($id)
{
$loc = Location::findOrFail($id);
$charts = $loc->charts;
$stats = [];
foreach ($charts as $c) {
$stats[$c['id']]['chartName'] = $c->name;
$stats[$c['id']]['chartUnit'] = $c->unit->symbol;
$stats[$c['id']]['stats'] = ChartStatistics::getChartStats($c['id']);
}
return response()->json(['allStats' => $stats]);
}
示例8: generateAddress
/**
* Generate an address for a location
* @param $location
* @return string
*/
private function generateAddress($location)
{
$locationName = $location->locationKeyCode;
$locationId = $location->id;
$location = $this->location->findOrFail($locationId);
$levelId = $location->level_id;
$level = $this->level_building->findOrFail($levelId);
$levelName = $level->levelName;
$building_id = $level->building_id;
$building = $this->building->findOrFail($building_id);
$buildingName = $building->buildingKeyCode;
$street_id = $building->street_id;
$street = $this->street->findOrFail($street_id);
$streetName = $street->streetKeyCode;
$agent_id = $street->agent_id;
$this->agent_id = $agent_id;
//$agent = $this->agent->findOrFail($agent_id);
$agentName = \App\Agent::where('user_id', '=', $agent_id)->first()->agentName;
return $buildingName . $levelName . $locationName . "-" . $streetName . " ( " . $agentName . " ) ";
}
示例9: getChartsByLocationId
public function getChartsByLocationId($id)
{
$location = Location::findOrFail($id);
$charts = $location->charts()->lists('name', 'id');
return response()->json(['charts' => $charts]);
}
示例10: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$location = Location::findOrFail($id);
$location->delete();
return redirect('locations');
}
示例11: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$location = \App\Location::findOrFail($id);
\Session::flash('flash_message', 'location ' . $location->name . ' deleted.');
// delete
$location->delete();
return redirect('locations');
}
示例12: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy(Request $request)
{
$rp_arr = [];
$user = \Auth::user();
if ($user->role->name != ('admin' or 'root')) {
// Permission denied
} else {
$data = $request->json()->get('data');
$lookUpArr = [];
for ($i = 0; $i < count($data); $i++) {
/*$from = Carbon::parse($data[$i]['from']);
$to = Carbon::parse($data[$i]['to']);
$location_id = \App\Location::where('name', $data[$i]['location'])->first()['id'];
\App\Order::where('from', $from)->where('to', $to)->where('location_id', $location_id)->delete();*/
$id = $data[$i]['id'];
$order = \App\Order::findOrFail($id);
array_push($lookUpArr, ['from' => $order->from, 'to' => $order->to, 'location_id' => $order->location_id]);
\App\Order::destroy($id);
}
$lookUpArr = array_unique($lookUpArr, SORT_REGULAR);
foreach ($lookUpArr as $value) {
$from = Carbon::parse($value['from']);
$to = Carbon::parse($value['to']);
$location_id = $value['location_id'];
$num_of_ordered = \App\Order::where('from', $from)->where('to', $to)->where('location_id', $location_id)->count();
$allowance = \App\Location::findOrFail($location_id)->capacity;
if ($num_of_ordered < $allowance) {
if ($num_of_ordered == 0) {
array_push($rp_arr, ['from' => $value['from'], 'to' => $value['to'], 'status' => '-1']);
} else {
array_push($rp_arr, ['from' => $value['from'], 'to' => $value['to'], 'status' => '1']);
}
} else {
array_push($rp_arr, ['from' => $value['from'], 'to' => $value['to'], 'status' => '0']);
}
}
}
return response()->json(['data' => $rp_arr]);
}
示例13: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$location = Location::findOrFail($id);
return view('locations.show', compact('location'));
}
示例14: handleDeleteLocation
public function handleDeleteLocation()
{
// Handle the delete confirmation.
$id = Input::get('location');
$location = Location::findOrFail($id);
$location->delete();
return Redirect::action('CommonController@locations');
}
示例15: edit
public function edit(Request $request)
{
$allLocationHierarhy = $this->location->getAllHierarhy(null, 0, 0);
$id = 0;
if (isset($request->id)) {
$id = $request->id;
}
$modelData = new \stdClass();
if ($id > 0) {
try {
$modelData = Location::findOrFail($id);
} catch (ModelNotFoundException $e) {
session()->flash('message', trans('admin_common.Invalid Location'));
return redirect(url('admin/location'));
}
}
$lid = 0;
if (isset($modelData->location_parent_id) && $modelData->location_parent_id > 0) {
$lid = $modelData->location_parent_id;
}
/**
* form is submitted check values and save if needed
*/
if ($request->isMethod('post')) {
/**
* validate data
*/
$rules = ['location_name' => 'required|max:255', 'location_slug' => 'required|max:255|unique:location,location_slug'];
if (isset($modelData->location_id)) {
$rules['location_slug'] = 'required|max:255|unique:location,location_slug,' . $modelData->location_id . ',location_id';
}
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
/**
* get data from form
*/
$data = $request->all();
/**
* save data if validated
*/
if (isset($data['location_active'])) {
$data['location_active'] = 1;
} else {
$data['location_active'] = 0;
}
if ($data['location_parent_id'] == 0) {
unset($data['location_parent_id']);
}
/**
* save or update
*/
if (!isset($modelData->location_id)) {
Location::create($data);
} else {
$modelData->update($data);
}
/**
* clear cache, set message, redirect to list
*/
Cache::flush();
session()->flash('message', trans('admin_common.Location saved'));
return redirect(url('admin/location'));
}
return view('admin.location.location_edit', ['l' => $allLocationHierarhy, 'modelData' => $modelData, 'lid' => $lid]);
}