laravel框架之修改
Posted songbao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel框架之修改相关的知识,希望对你有一定的参考价值。
//控制器層
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框架之修改的主要内容,如果未能解决你的问题,请参考以下文章