php - Laravel 5 - why is input empty when returning with errors? -
i have form submits controller, validates data. if validation fails redirects input , errors. method deals form submission:
<?php namespace app\http\controllers; use illuminate\http\request; use app\models\user; class usercontroller extends controller { /** * create new user. * * @param reqeust $request * * @return void */ public function postcreate(request $request) { $user = new user; $rules = $user->rules(); $rules['password'] = 'required|confirmed|min:8'; $v = \validator::make($request->except('_token', 'roles'), $rules); if ($v->fails()) { return redirect()->back()->withinput($request->except('_token', 'password', 'password_confirmation'))->witherrors($v); } $user->fill($request->except('_token', 'password', 'password_confirmation')); $user->password = \hash::make($request->input('password')); $user->save(); return redirect()->route('webmanaccounts')->with('messages', [['text' => 'user account created', 'class' => 'alert-success']]); }
on page displays form check see if name
, 1 of fields, present , if populate user object data. problem input
empty.
<?php namespace backend; use illuminate\http\request; use illuminate\support\facades\request requestfacade; use app\http\controllers\controller; use app\models\role; use app\models\user; class usercontroller extends controller { public function __construct(request $request) { if ( ! $request->user()->can('accounts')) { return abort(403, 'you not have permission access page.'); } } /** * display create new user form , process error messages. * * @param reqeust $request * * @return view */ public function create(request $request) { $user = new user; dump(requestfacade::all()); if (requestfacade::has('name')) { $user->fill(requestfacade::except('_token', 'roles')); foreach (requestfacade::only('roles') $role) { $user->roles()->add($role); } } return view('backend.user.create', ['title' => 'website manager :: create new account', 'user' => $user, 'roles' => role::all()]); }
i have tried requestfacade
, $request
, input
, show empty. why isn't data being passed back?
to add strangeness of this, have project uses identical code , works fine. why work fine 1 project not another!?
when use withinput()
method, data flashed session "old" data.
$request->old()
should give array of "old" data.
$request->old('name')
should give "old" name data.
Comments
Post a Comment