本文整理汇总了PHP中Car::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::findOrFail方法的具体用法?PHP Car::findOrFail怎么用?PHP Car::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::findOrFail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified car in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$car = Car::findOrFail($id);
$validator = Validator::make($data = Input::all(), Car::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$car->reg_no = Input::get('reg_no');
$car->make = Input::get('make');
$car->driver = Input::get('driver');
$car->status = 'available';
$car->driver_contact = Input::get('driver_contact');
$car->update();
return Redirect::route('cars.index');
}
示例2: update
/**
* Update the specified booking in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$booking = Booking::findOrFail($id);
$validator = Validator::make($data = Input::all(), Booking::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$client = Client::findOrFail(Input::get('client_id'));
$car = Car::findOrFail(Input::get('car_id'));
$booking->client()->associate($client);
$booking->car()->associate($car);
$booking->destination = Input::get('destination');
$booking->date_out = Input::get('date_out');
$booking->date_back = Input::get('date_back');
$booking->update();
return Redirect::route('bookings.index');
}
示例3: update
/**
* Update the specified car in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$userId = Auth::user()->id;
$carData = Car::find($id);
if ($userId === $carData["user_id"]) {
$car = Car::findOrFail($id);
$messages = array('new_make.required' => 'Make field cannot be left empty.', 'new_make.max' => 'You must enter a value with a maximum of 255 characters.', 'new_model.required' => 'Model field cannot be left empty.', 'new_model.max' => 'You must enter a value with a maximum of 255 characters.', 'new_license_plate_number.required' => 'License Plate Number field cannot be left empty.', 'new_license_plate_number.max' => 'You must enter a value with a maximum of 255 characters.', 'new_color.required' => 'Color field cannot be left empty.', 'new_color.max' => 'You must enter a value with a maximum of 255 characters.');
$validator = Validator::make($data = Input::all(), Car::$new_rules, $messages);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
} else {
$car->make = Input::get('new_make');
$car->model = Input::get('new_model');
$car->license_plate_number = Input::get('new_license_plate_number');
$car->color = Input::get('new_color');
$result = $car->save();
}
if ($result) {
Session::flash('successMessage', 'Your vehicle was successfully updated');
return Redirect::route('cars.index');
} else {
Session::flash('errorMessage', 'Please properly input all the required fields');
Log::warning('Vehicle failed to save: ', Input::all());
return Redirect::back()->withInput();
}
} else {
return "Access Denied: this is not your car.";
}
}