Php 如何更新“pay”laravel记录?

Php 如何更新“pay”laravel记录?,php,mysql,laravel,laravel-5,Php,Mysql,Laravel,Laravel 5,我试图在按下表行中的按钮后更新数据库中的“pay”记录,但按下按钮时显示此错误: 0db55b8fee884912074e1a4700061051aeb18bcc.php行中出现错误异常 15:未定义变量:用户视图: /Users/mauricio/code/cnr/resources/views/pages/Users.blade.php 我不知道当我在blade文件中使用users变量时,它为什么会给我这个错误 这是我的注册管理员: <?php namespace App\Http\C

我试图在按下表行中的按钮后更新数据库中的“pay”记录,但按下按钮时显示此错误:

0db55b8fee884912074e1a4700061051aeb18bcc.php行中出现错误异常 15:未定义变量:用户视图: /Users/mauricio/code/cnr/resources/views/pages/Users.blade.php

我不知道当我在blade文件中使用users变量时,它为什么会给我这个错误

这是我的注册管理员:

<?php
namespace App\Http\Controllers;
use DB;
use App\User;

class RegistrationController extends Controller
{

    public function updatePay(User $id)
    {
        DB::table('users')->where('id', $id)->update(['pay' => 1]);

        return view('pages.users');
    }

}
public function usersAdmin()
{
    $users = DB::table('users')->get();

    return view('pages.users', compact('users'));
}
路由文件:

// for admin only
Route::get('/users', 'WelcomeController@usersAdmin');
Route::post('/users/{id}', 'RegistrationController@updatePay');
这是我的看法

@extends('layouts.master')
@section('content')

<table class="highlight">
    <thead>
        <tr>
            <th data-field="id" hidden="">ID</th>
            <th data-field="name">Nombre</th>
            <th data-field="last_name">Apellidos</th>
            <th style="text-align: right;">Acciones</th>
        </tr>
    </thead>

    <tbody>

        @foreach($users as $user)
            <tr>
                <td>{{$user->id}}</td>
                <td>{{$user->name}}</td>
                <td>{{$user->last_name}}</td>
                <td style="text-align: right; width: 30em">
                    @if( $user->isAdmin )
                        {{"ADMINISTRADOR"}}
                    @elseif( $user->pay )
                        <a class="waves-effect waves-light btn yellow darken-2"><i class="material-icons left" style="margin:0">create</i></a>
                        <a class="waves-effect waves-light btn red darken-1"><i class="material-icons left" style="margin:0">delete</i></a>
                    @else
                        <form method="POST" action="/users/{{$user->id}}">
                            {{ csrf_field() }}
                            <button type="submit" class="waves-effect waves-light btn green lighten-1"><i class="material-icons left" style="margin:0">done</i></button>
                        </form>
                    @endif
                </td>
            </tr>
        @endforeach

    </tbody>
</table>

@endsection

您需要检索用户并将其发送到类似以下内容的视图:

控制器:

此外,您还有两种选择:

首先

第二


而不是返回“pages.users”视图;使用返回重定向->url“用户”;在updatePay方法中。

我已经在数据库中显示了我的用户,我需要更新用户行中的记录。在按下按钮进行更新之前,一切都很好谢谢你,很明显我看不到它。
public function methodName()
{
  $users = User::all();
  return view('path.to.view')->with(compact('users'));
}
public function updatePay($id)
public function updatePay(User $user)
{
    DB::table('users')->where('id', $user->id)->update(['pay' => 1]);