public function testBasic() { $request = new Request(['method' => 'POST', 'queryString' => 'a=b&b=c', 'content' => json_encode(['foo' => 'bar']), 'headers' => ['Content-Type' => 'application/json; Charset=utf8']]); $this->assertTrue($request->is('post')); $this->assertEquals(['a' => 'b', 'b' => 'c'], $request->params->all()); $this->assertEquals(['foo' => 'bar'], $request->body->all()); $this->assertEquals('b', $request->input('a')); $this->assertEquals(true, $request->has('foo')); }
public function store(Request $request, Response $response) { $rules = ['name' => 'required']; $validator = app('validation')->make($request->all(), $rules); if ($validator->fails()) { $request->session->add(['errors' => $validator->errors()->all()]); return app('twig')->render('pads/create.htm'); } $pad = new Pad(); $pad->name = $request->input('name'); $pad->user_id = $request->user()->id; $pad->save(); $request->session->add(['success' => 'Pad saved successfuly.']); return $response->redirect("/pads/{$pad->id}/update"); }
public function store(Request $request, Response $response) { $rules = ['name' => 'required', 'text' => 'required', 'pad' => 'required|exists:pads,id']; $validator = app('validation')->make($request->all(), $rules); if ($validator->fails()) { $request->session->add(['errors' => $validator->errors()->all()]); return app('twig')->render('notes/create.htm', ['oldInputs' => $request->all()]); } $note = new Note(); $note->name = $request->input('name'); $note->text = $request->input('text'); $note->user_id = $request->user()->id; $note->pad_id = $request->input('pad'); $note->save(); $request->session->add(['success' => 'Note saved successfuly.']); return $response->redirect("/notes/{$note->id}/update"); }
public function updateSettings(Request $request, Hash $hash) { $user = $request->user(); $rules = ['old_password' => 'required|min:8', 'password' => 'required|confirmed|min:8']; $validator = app('validation')->make($request->all(), $rules); if ($validator->fails()) { $request->session->add(['errors' => $validator->errors()->all()]); return app('twig')->render('user/settings.htm', ['oldInputs' => $request->all()]); } if (!$hash->check($request->input('old_password'), $user->password)) { $request->session->add(['errors' => ['Old password incorrect.']]); return app('twig')->render('user/settings.htm', ['oldInputs' => $request->all()]); } $user->password = $hash->make($request->input('old_password')); $user->save(); $request->session->add(['success' => 'settings updated successfuly.']); return app('twig')->render('user/settings.htm'); }