Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppHttpControllers;
- use IlluminateHttpRequest;
- use AppHttpRequests;
- use IlluminateSupportFacadesValidator;
- use IlluminateSupportFacadesInput;
- use IlluminateSupportFacadesRedirect;
- use IlluminateSupportFacadesView;
- use AppUser;
- class UsersController extends Controller
- {
- public function create(){
- return view('create');
- }
- public function store(){
- $rules = array(
- 'name' => 'required|unique:users',
- 'email' => 'required|unique:users',
- 'password' => 'required|min:5'
- );
- $validator = Validator::make(Input::all(),$rules);
- if($validator->fails()){
- return Redirect::to('http://localhost/laravelking/users/create')->withInput()->withErrors($validator);
- }else{
- User::create(array(
- 'name' => Input::get('name'),
- 'email' => Input::get('email'),
- 'password' => Input::get('password')
- ));
- return Redirect::to('http://localhost/laravelking/users');
- }
- }
- public function index(){
- return view::make('users')->withUsers(User::all());
- }
- public function show($id){
- $user = User::find($id);
- if($user == null){
- return Redirect::to('http://localhost/laravelking/users');
- }else{
- return View::make('profile')->withUser($user);
- }
- return 'list '.$id;
- }
- public function update($id){
- $rules = array(
- 'name' => 'required|unique:users',
- 'email' => 'required|unique:users',
- 'password' => 'required|min:5'
- );
- $validator = Validator::make(Input::all(),$rules);
- if($validator->fails()){
- return Redirect::to('http://localhost/laravelking/users/'.$id.'/edit')->withInput()->withErrors($validator);
- }else{
- $user = User::find($id);
- if(Input::has('name')) $user->name = Input::get('name');
- if(Input::has('email')) $user->email = Input::get('email');
- if(Input::has('password')) $user->password = Input::get('password');
- $user->save();
- return Redirect::to('http://localhost/laravelking/users/'.$id);
- }
- }
- public function edit($id){
- $user = User::find($id);
- if($user == null){
- return Redirect::to('http://localhost/laravelking/users');
- }else{
- return View::make('edit')->with('id',$id);
- }
- }
- public function delete($id){
- return 'list'.$id;
- }
- }
- <form role="form" method="PUT" action="users/".$id>
- <input type="hidden" name="_token" value="{{ csrf_token() }}">
- <div class="form-group">
- <label for="username">New Name:</label>
- <input type="username" class="form-control" name="name" id="name">
- </div>
- <div class="form-group">
- <label for="email">New Email address:</label>
- <input type="email" name="email" class="form-control" id="email">
- </div>
- <div class="form-group">
- <label for="pwd">New Password:</label>
- <input type="password" name="password" class="form-control" id="pwd">
- </div>
- <div class="checkbox">
- <label><input type="checkbox"> Remember me</label>
- </div>
- <button type="submit" class="btn btn-default">Update</button>
- </form>
- <div class="container">
- <div class="col-md-8 col-lg-8 col-sm-12">
- <div class="jumbotron">
- <h1> Hello {!! $user->name !!}</h1>
- <h3> Your Email is {!! $user->email !!}</h3>
- <h3 style="color:red"> Your Password is {!! $user->password !!}</h3>
- <h1> {!! Html::link('users/'.$user->id.'/edit','Edit ') !!}</h1>
- </div>
- </div>
- </div>
- Route::group(['middleware' => ['web']], function () {
- //
- Route::resource('users','UsersController');
- });
- http://localhost/laravelking/users/1?_token=wazgR1tQaznQwRdejXdx4g3jLgbtlfPLIeIiXdRy&name=Lololololol&email=Lololololol%40gaic.com&password=Lololololol
- <form action="{{url('users/' . $id)}}" ... >
- <input name="_method" type="hidden" value="PUT">
- // Plain PHP
- echo method_field('PUT');
- //Blade template engine
- {{ method_field('PUT') }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement