• laravel框架之修改


     1 //控制器層
     2 public function update(request $request)
     3 {
     4     $id = $request->get('id');
     5     $data = DB::select("select * from users where id='$id'");
     6     $data = json_encode($data);
     7     $data = json_decode($data,1);
     8     return view('admin.update',['data'=>$data]);
     9 }
    10 public function update_do(request $request)
    11 {
    12     $id = $request->post('id');
    13     $data = $request->only(['username','password','email']);
    14     DB::table('users')->where('id',$id)->update($data);
    15     return redirect()->route("admin.showlist");
    16 }
     1 //跳轉頁面
     2 <td><a href="javascript:void (0)" id="{{$val->id}}" class="del">刪除</a>|<a href="update?id={{$val->id }}">編輯</a></td>
     3 //視圖層
     4 @extends('layouts.app')
     5 @section('title','修改頁面')
     6 @section('content')
     7     <div class="container">
     8         <div class="row justify-content-center">
     9             <div class="col-md-8">
    10                 <div class="card">
    11                     <div class="card-header">{{ __('Update') }}</div>
    12 
    13                     <div class="card-body">
    14                         <form method="POST" action="{{ route('admin.update_do') }}" aria-label="{{ __('Update') }}">
    15                             @csrf
    16                             <input type="hidden" id="id" name="id" value="{{$data[0]['id']}}">
    17                             <div class="form-group row">
    18                                 <label for="username" class="col-md-4 col-form-label text-md-right">{{ __('UserName') }}</label>
    19 
    20                                 <div class="col-md-6">
    21                                     <input id="username" type="text" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" name="username"  value="<?php echo $data[0]['username']?>" required autofocus>
    22 
    23                                     @if ($errors->has('username'))
    24                                         <span class="invalid-feedback" role="alert">
    25                                         <strong>{{ $errors->first('username') }}</strong>
    26                                     </span>
    27                                     @endif
    28                                 </div>
    29                             </div>
    30 
    31                             <div class="form-group row">
    32                                 <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
    33 
    34                                 <div class="col-md-6">
    35                                     <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{$data[0]['email']}}" required>
    36 
    37                                     @if ($errors->has('email'))
    38                                         <span class="invalid-feedback" role="alert">
    39                                         <strong>{{ $errors->first('email') }}</strong>
    40                                     </span>
    41                                     @endif
    42                                 </div>
    43                             </div>
    44 
    45                             <div class="form-group row">
    46                                 <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
    47 
    48                                 <div class="col-md-6">
    49                                     <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password"  value="{{$data[0]['password']}}" required>
    50 
    51                                     @if ($errors->has('password'))
    52                                         <span class="invalid-feedback" role="alert">
    53                                         <strong>{{ $errors->first('password') }}</strong>
    54                                     </span>
    55                                     @endif
    56                                 </div>
    57                             </div>
    58 
    59                             <div class="form-group row">
    60                                 <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
    61 
    62                                 <div class="col-md-6">
    63                                     <input id="password-confirm" type="password" class="form-control" name="password_confirmation" value="{{$data[0]['password']}}" required>
    64                                 </div>
    65                             </div>
    66 
    67                             <div class="form-group row mb-0">
    68                                 <div class="col-md-6 offset-md-4">
    69                                     <button type="submit" class="btn btn-primary">
    70                                         {{ __('Updated') }}
    71                                     </button>
    72                                 </div>
    73                             </div>
    74                         </form>
    75                     </div>
    76                 </div>
    77             </div>
    78         </div>
    79     </div>
    80 @endsection
  • 相关阅读:
    According to TLD or attribute directive in tag file, attribute end does not accept any expressions
    Several ports (8080, 8009) required by Tomcat v6.0 Server at localhost are already in use.
    sql注入漏洞
    Servlet—简单的管理系统
    ServletContext与网站计数器
    VS2010+ICE3.5运行官方demo报错----std::bad_alloc
    java 使用相对路径读取文件
    shell编程 if 注意事项
    Ubuntu12.04下eclipse提示框黑色背景色的修改方法
    解决Ubuntu环境变量错误导致无法正常登录
  • 原文地址:https://www.cnblogs.com/songbao/p/11188723.html
Copyright © 2020-2023  润新知