我想在同一页面上显示和编辑数据库中的数据

时间:2019-05-13 10:43:08

标签: laravel

我有一个数据库表“ users”,里面有“ id”,“ nick”和“ points”,我想显示数据并在同一页面上进行编辑,我想出了如何显示数据,但是我无法编辑

这是名为gestpointscontrol.blade的刀片服务器

@extends('layouts.app')
@section('content')
<div class="container">
<meta charset="utf-8" />
@if(!Auth::guest())
<body>

    {!!Form::open(['action'=>['RankingController@update',$uid], 'method' => 'PUT'])!!}
@foreach ($users as $user)

    {{Form::label('nick', 'Nick')}}
    {{Form::text('nick', $user->nick, ['class' => 'form-control', 'col-md-4'])}}
    {{Form::label('points', 'Points')}}
    {{Form::text('points', $user->points, ['class' => 'form-control', 'col-md-4'])}}

@endforeach

    {{Form::submit('update', ['class'=>'btn btn-primary'])}} 
{!! Form::close() !!}

@endif
  <br>
</body> 
 </html>
</div>

@endsection

控制器排名控制器



public function update(Request $request, $id)
    {
        $this->validate($request, [
            'nick' => 'required',
            'points' => 'required',
        ]);


        $users = User::find($id);
        $users->nick = $request->input('nick');
        $users->points = $request->input('points');
        $users->save();


        return redirect('/gestpointscontrol');

    }

public function edit()
    {
        $users = User::all();
        return view('admin.gestpointscontrol')->with('users', $users);

    }

0 个答案:

没有答案