码迷,mamicode.com
首页 > 其他好文 > 详细

laravel框架之修改

时间:2019-07-15 14:41:56      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:HERE   ofo   tle   class   require   first   users   extends   res   

//控制器層
public function update(request $request)
{
$id = $request->get(‘id‘);
$data = DB::select("select * from users where id=‘$id‘");
$data = json_encode($data);
$data = json_decode($data,1);
return view(‘admin.update‘,[‘data‘=>$data]);
}
public function update_do(request $request)
{
$id = $request->post(‘id‘);
$data = $request->only([‘username‘,‘password‘,‘email‘]);
DB::table(‘users‘)->where(‘id‘,$id)->update($data);
return redirect()->route("admin.showlist");
}

//跳轉頁面
<td><a href="javascript:void (0)" id="{{$val->id}}" class="del">刪除</a>|<a href="update?id={{$val->id }}">編輯</a></td>
//視圖層
@extends(‘layouts.app‘)
@section(‘title‘,‘修改頁面‘)
@section(‘content‘)
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __(‘Update‘) }}</div>

<div class="card-body">
<form method="POST" action="{{ route(‘admin.update_do‘) }}" aria-label="{{ __(‘Update‘) }}">
@csrf
<input type="hidden" id="id" name="id" value="{{$data[0][‘id‘]}}">
<div class="form-group row">
<label for="username" class="col-md-4 col-form-label text-md-right">{{ __(‘UserName‘) }}</label>

<div class="col-md-6">
<input id="username" type="text" class="form-control{{ $errors->has(‘username‘) ? ‘ is-invalid‘ : ‘‘ }}" name="username" value="<?php echo $data[0][‘username‘]?>" required autofocus>

@if ($errors->has(‘username‘))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first(‘username‘) }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __(‘E-Mail Address‘) }}</label>

<div class="col-md-6">
<input id="email" type="email" class="form-control{{ $errors->has(‘email‘) ? ‘ is-invalid‘ : ‘‘ }}" name="email" value="{{$data[0][‘email‘]}}" required>

@if ($errors->has(‘email‘))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first(‘email‘) }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __(‘Password‘) }}</label>

<div class="col-md-6">
<input id="password" type="password" class="form-control{{ $errors->has(‘password‘) ? ‘ is-invalid‘ : ‘‘ }}" name="password" value="{{$data[0][‘password‘]}}" required>

@if ($errors->has(‘password‘))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first(‘password‘) }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __(‘Confirm Password‘) }}</label>

<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" value="{{$data[0][‘password‘]}}" required>
</div>
</div>

<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __(‘Updated‘) }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection

laravel框架之修改

标签:HERE   ofo   tle   class   require   first   users   extends   res   

原文地址:https://www.cnblogs.com/songbao/p/11188723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!