本文整理汇总了PHP中app\Country::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Country::findOrFail方法的具体用法?PHP Country::findOrFail怎么用?PHP Country::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Country
的用法示例。
在下文中一共展示了Country::findOrFail方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(EditCountryRequest $request, $id)
{
$country = Country::findOrFail($id);
$country->fill($request->all());
$country->save();
return redirect()->route('settings.country.index');
}
示例2: show
public function show($id)
{
$links[1] = 'active';
try {
$country = Country::findOrFail($id);
} catch (ModelNotFoundException $ex) {
return view('errors.404');
}
return view('country.show', ['country' => $country, 'links' => $links]);
}
示例3: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($country_id)
{
$statusCode = 200;
$response = ['cities' => []];
Country::findOrFail($country_id);
$cities = City::with('country')->where('country_id', '=', $country_id)->get();
foreach ($cities as $city) {
$response['cities'][] = ['id' => $city->id, 'city' => $city->city, 'country_id' => $country_id, 'country' => $city->country->country];
}
return response($response, $statusCode);
}
示例4: show
public function show($alpha2, $id)
{
$links[1] = 'active';
try {
$bank = Bank::findOrFail($id);
$country = Country::findOrFail($alpha2);
} catch (ModelNotFoundException $ex) {
return view('errors.404');
}
return view('bank.show', ['bank' => $bank, 'country' => $country, 'links' => $links]);
}
示例5: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$country = Country::findOrFail($id);
$country->delete();
$statusCode = 200;
$response = ["success" => "Country {$id} successfully destroyed"];
return response($response, $statusCode);
}
示例6: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, Request $request)
{
//$this->validate($request, ['name' => 'required']); // Uncomment and modify if needed.
$country = Country::findOrFail($id);
$update = $request->all();
// is new image uploaded?
if ($file = Input::file('image')) {
$fileName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension() ?: 'png';
$folderName = '/uploads/';
$destinationPath = Config::get('app.path') . $folderName;
$safeName = time() . "_" . str_random(10) . '.' . $extension;
$file->move($destinationPath, $safeName);
//delete old pic if exists
if (File::exists(Config::get('app.path') . $country->image)) {
File::delete(Config::get('app.path') . $country->image);
}
$update['image'] = $safeName ? $folderName . $safeName : '';
}
if (isset(Country::$boolean)) {
foreach (Country::$boolean as $field) {
if (isset($update[$field]) && $update[$field] == "on") {
$update[$field] = 1;
} else {
$update[$field] = 0;
}
}
}
$country->update($update);
return redirect('admin/countries')->with('success', Lang::get('message.success.update'));
}
示例7: findById
/**
* Find a country by id.
*
* @param int $id
* @return Country
* @throws ModelNotFoundException
*/
public function findById($id)
{
return Country::findOrFail($id);
}
示例8: findCountry
public function findCountry($countryId)
{
return Country::findOrFail($countryId);
}
示例9: getCountryDetails
/**
* Get the Detail Info about individual country
*/
public function getCountryDetails($id, $name)
{
$sortableColumns = ['position', 'rank_id', 'name', 'player_rating', 'total_score', 'total_points', 'total_time_played', 'last_game_id'];
$orderBy = Request::has('orderBy') && in_array(Request::get('orderBy'), $sortableColumns) ? Request::get('orderBy') : 'position';
$sortDir = Request::has('direction') ? Request::get('direction') : 'asc';
//$players = PlayerTotal::orderBy($orderBy,$sortDir)->paginate(10);
$country = Country::findOrFail($id);
$players = $country->playerTotals()->orderBy($orderBy, $sortDir)->with('country', 'rank', 'lastGame')->paginate(35);
$array = ['players' => $players, 'countryName' => $country->countryName, 'countryId' => $country->id];
return view('statistics.country-players', $array);
}
示例10: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$country = Country::findOrFail($id);
$country->delete();
return redirect('country');
}
示例11: posts
public function posts($id)
{
$country = Country::findOrFail($id);
return view('country.posts', compact('country'));
}