私はテーブルの行のボタンを押した後、DBでの私の「給料」レコードを更新しようとしているが、ボタンを押したときには、このエラーを示していますレコード 'pay' laravelを更新するには?
0db55b8fee884912074e1a4700061051aeb18bcc.phpラインでErrorException 15:未定義の変数:ユーザー(閲覧: /Users/mauricio/code/cnr/resources/views/pages/users.blade.php)
それは私にそのエラーを与え、なぜ私が使用していたとき、私は知りませんユーザーはブレードファイル内の前に変数を変更します。ここで
は私の登録コントローラーです:
<?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', '[email protected]');
Route::post('/users/{id}', '[email protected]');
ここでは、私の見解では
@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="https://stackoverflow.com/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
です
私はすでにDBに自分のユーザーを表示しています。ユーザ行のレコードを更新する必要があります。更新のためにボタンを押す前に、averythingはうまく動作します –
私の答えを更新します。それを試してみてください。 – MohamedSabil83
ありがとう、私はそれを見ることができなかったことはとても明らかでした。 –