Guest User

Untitled

a guest
Nov 15th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. function getCreateUser(){
  2. $config = array(
  3. 'pageName' => 'createUser',
  4. 'pageTitle' => 'Create User',
  5. 'formUrl' => action('UsersController@postCreateUser'),
  6. 'modelFields' => array(
  7. array('db_name' => 'employee_id', 'text' => 'Employee Id', 'mandatory' => TRUE),
  8. array('db_name' => 'full_name', 'text' => 'Full Name', 'mandatory' => TRUE),
  9. array('db_name' => 'email', 'text' => 'Email', 'mandatory' => FALSE),
  10. array('db_name' => 'password', 'text' => 'Password','value' => '12345', 'mandatory' => TRUE)
  11. ),
  12. 'submit_text' => 'Create'
  13. );
  14. return View::make('layouts.form', $config);
  15. }
  16.  
  17. function postCreateUser(){
  18. $config = array(
  19. 'pageName' => 'createUser',
  20. 'pageTitle' => 'Create User',
  21. 'formUrl' => action('UsersController@postCreateUser'),
  22. 'modelFields' => array(
  23. array('db_name' => 'employee_id', 'text' => 'Employee Id', 'mandatory' => TRUE),
  24. array('db_name' => 'full_name', 'text' => 'Full Name', 'mandatory' => TRUE),
  25. array('db_name' => 'email', 'text' => 'Email', 'mandatory' => FALSE),
  26. array('db_name' => 'password', 'text' => 'Password','value' => '12345', 'mandatory' => TRUE)
  27. ),
  28. 'submit_text' => 'Create'
  29. );
  30. $validator = User::validate(Input::all());
  31. if($validator->passes()){
  32. $user = new User(Input::all());
  33. $user->password = Hash::make(Input::get('password'));
  34. $user->Company_id = '1';
  35. $user->save();
  36.  
  37. Session::flash('message', 'User Created Successfully!');
  38. Session::flash('alert-class', 'alert-success');
  39. return View::make('layouts.form', $config);
  40. }
  41.  
  42. return View::make('layouts.form', $config)->withErrors($validator->messages());
  43. }
  44.  
  45. @if ( $errors->count() > 0 )
  46. <div class="alert alert-danger">
  47. <p>The following errors have occurred:</p>
  48.  
  49. <ul>
  50. @foreach( $errors->all() as $message )
  51. <li>{{ $message }}</li>
  52. @endforeach
  53. </ul>
  54. </div>
  55. @endif
  56.  
  57. @if(Session::has('message'))
  58. <p class="alert {{ Session::get('alert-class', 'alert-info') }} alert-dismissable"> {{ Session::get('message') }}</p>
  59. @endif
  60.  
  61. function postCreateUser(){
  62. $validator = User::validate(Input::all());
  63. if($validator->passes()){
  64. $user = new User(Input::all());
  65. $user->password = Hash::make(Input::get('password'));
  66. $user->Company_id = '1';
  67. $user->save();
  68.  
  69. Session::flash('message', 'User Created Successfully!');
  70. Session::flash('alert-class', 'alert-success');
  71. } else {
  72. Session::flash('message', Helpers::formatErrors($validator->messages()->all()));
  73. Session::flash('alert-class', 'alert-danger');
  74. }
  75.  
  76. return Redirect::action('UsersController@getCreateUser');
  77. }
  78.  
  79. Session::flash($key, $value);
  80. Session::push('flash.old', $key);
  81.  
  82. Input::flashExcept('_token');
  83.  
  84. Session::forget('_old_input');
  85.  
  86. session()->now()
  87.  
  88. View::make( 'view.name' )->withOldFormData( Input::all() );
  89.  
  90. {{ Form::model( $old_form_data ) }}
Add Comment
Please, Sign In to add comment