Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppHttpControllers;
  4.  
  5. use IlluminateHttpRequest;
  6.  
  7. use AppHttpRequests;
  8.  
  9. use IlluminateSupportFacadesValidator;
  10.  
  11. use IlluminateSupportFacadesInput;
  12.  
  13. use IlluminateSupportFacadesRedirect;
  14.  
  15. use IlluminateSupportFacadesView;
  16.  
  17. use AppUser;
  18.  
  19. class UsersController extends Controller
  20. {
  21. public function create(){
  22. return view('create');
  23. }
  24.  
  25. public function store(){
  26. $rules = array(
  27. 'name' => 'required|unique:users',
  28. 'email' => 'required|unique:users',
  29. 'password' => 'required|min:5'
  30.  
  31. );
  32. $validator = Validator::make(Input::all(),$rules);
  33.  
  34. if($validator->fails()){
  35. return Redirect::to('http://localhost/laravelking/users/create')->withInput()->withErrors($validator);
  36. }else{
  37. User::create(array(
  38. 'name' => Input::get('name'),
  39. 'email' => Input::get('email'),
  40. 'password' => Input::get('password')
  41. ));
  42. return Redirect::to('http://localhost/laravelking/users');
  43. }
  44.  
  45. }
  46.  
  47. public function index(){
  48. return view::make('users')->withUsers(User::all());
  49. }
  50. public function show($id){
  51. $user = User::find($id);
  52.  
  53. if($user == null){
  54. return Redirect::to('http://localhost/laravelking/users');
  55. }else{
  56. return View::make('profile')->withUser($user);
  57. }
  58. return 'list '.$id;
  59. }
  60. public function update($id){
  61. $rules = array(
  62. 'name' => 'required|unique:users',
  63. 'email' => 'required|unique:users',
  64. 'password' => 'required|min:5'
  65.  
  66. );
  67. $validator = Validator::make(Input::all(),$rules);
  68.  
  69. if($validator->fails()){
  70. return Redirect::to('http://localhost/laravelking/users/'.$id.'/edit')->withInput()->withErrors($validator);
  71. }else{
  72. $user = User::find($id);
  73. if(Input::has('name')) $user->name = Input::get('name');
  74. if(Input::has('email')) $user->email = Input::get('email');
  75. if(Input::has('password')) $user->password = Input::get('password');
  76. $user->save();
  77. return Redirect::to('http://localhost/laravelking/users/'.$id);
  78. }
  79. }
  80. public function edit($id){
  81. $user = User::find($id);
  82. if($user == null){
  83. return Redirect::to('http://localhost/laravelking/users');
  84. }else{
  85. return View::make('edit')->with('id',$id);
  86. }
  87. }
  88.  
  89. public function delete($id){
  90. return 'list'.$id;
  91. }
  92. }
  93.  
  94. <form role="form" method="PUT" action="users/".$id>
  95. <input type="hidden" name="_token" value="{{ csrf_token() }}">
  96. <div class="form-group">
  97. <label for="username">New Name:</label>
  98. <input type="username" class="form-control" name="name" id="name">
  99. </div>
  100. <div class="form-group">
  101. <label for="email">New Email address:</label>
  102. <input type="email" name="email" class="form-control" id="email">
  103. </div>
  104. <div class="form-group">
  105. <label for="pwd">New Password:</label>
  106. <input type="password" name="password" class="form-control" id="pwd">
  107. </div>
  108. <div class="checkbox">
  109. <label><input type="checkbox"> Remember me</label>
  110. </div>
  111. <button type="submit" class="btn btn-default">Update</button>
  112. </form>
  113.  
  114. <div class="container">
  115. <div class="col-md-8 col-lg-8 col-sm-12">
  116. <div class="jumbotron">
  117. <h1> Hello {!! $user->name !!}</h1>
  118. <h3> Your Email is {!! $user->email !!}</h3>
  119. <h3 style="color:red"> Your Password is {!! $user->password !!}</h3>
  120. <h1> {!! Html::link('users/'.$user->id.'/edit','Edit ') !!}</h1>
  121. </div>
  122. </div>
  123. </div>
  124.  
  125. Route::group(['middleware' => ['web']], function () {
  126. //
  127. Route::resource('users','UsersController');
  128. });
  129.  
  130. http://localhost/laravelking/users/1?_token=wazgR1tQaznQwRdejXdx4g3jLgbtlfPLIeIiXdRy&name=Lololololol&email=Lololololol%40gaic.com&password=Lololololol
  131.  
  132. <form action="{{url('users/' . $id)}}" ... >
  133.  
  134. <input name="_method" type="hidden" value="PUT">
  135.  
  136. // Plain PHP
  137. echo method_field('PUT');
  138.  
  139. //Blade template engine
  140. {{ method_field('PUT') }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement