Пример #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $car = new \App\Car();
     // populate the model with the form data
     $car->make = $request->make;
     $car->model = $request->model;
     $car->produced_on = $request->produced_on;
     // save the model to create a new object in the database
     if (!$car->save()) {
         $errors = $car->getErrors();
         return redirect()->route('cars.create')->with('errors', $errors)->withInput();
     }
     // success!
     return redirect()->route('cars.create')->with('message', 'Your ' . $car->make . ' ' . $car->model . ' from ' . $car->produced_on . ' has been created!');
 }
Пример #2
0
 public function testAddRepairDateFail3()
 {
     $user = App\User::all()->last();
     $count = App\Repair::count();
     $this->actingAs($user)->visit('/repairs/create')->select(App\Car::all()->last()->LicencePlate, 'LicencePlate')->select(App\Staff::all()->last()->Id, 'StaffId')->check('Ongoing')->type('Oil change', 'Type')->type('Just a routine exercise.', 'Comments')->type('2016-02-14asd', 'StartDate')->type('2016/02/16', 'EndDate')->type('50', 'Cost')->press('Add repair');
     $this->assertEquals($count, App\Repair::count());
 }
Пример #3
0
 /**
  * Responds to requests to POST /cars/create
  */
 public function postCreate(Request $request)
 {
     $this->validate($request, ['year' => 'required|numeric|between:1900,2100', 'model' => 'required|min:2', 'style' => 'required|min:1', 'picture' => 'required|url', 'purchase_link' => 'url', 'price' => 'numeric|between:1,500000']);
     # Insert car record into database
     $car = new \App\Car();
     $car->model = $request->model;
     $car->style = $request->style;
     $car->price = $request->price;
     $car->manufacturer_id = $request->manufacturer;
     $car->size_id = $request->size;
     $car->user_id = \Auth::id();
     $car->picture = $request->picture;
     $car->year = $request->year;
     $car->purchase_link = $request->purchase_link;
     $car->save();
     # Add the tags
     if ($request->tags) {
         $tags = $request->tags;
     } else {
         $tags = [];
     }
     $car->tags()->sync($tags);
     # Inform the user
     \Session::flash('flash_message', 'Your car of interest was added!');
     return redirect('/cars');
 }