我收到的错误消息是:
ErrorException (E_ERROR) Undefined variable: userdata
我知道这些事情经常被问到。我已经搜索过Google,并且在这里已经尝试了建议的答案,但无济于事。
控制器:
public function index()
{
$userdata = EditUserModel::all()->paginate(5);
return view('admin.userman')->with(['userdata' => $userdata])->with('i', (request()->input('page', 1) - 1) * 5);
}
路线:
Route::resource('admin.userman', 'EditUserController');
型号:
public class EditUserModel extends Model
{
public $table = "users";
protected $fillable = [
'id',
'name',
'email',
'role',
'password'
];
}
查看:
@foreach($userdata as $data)
<tbody>
<tr>
<td>{{ $data->id }}</td>
<td>{{ $data->email }}</td>
<td>{{ $data->created_at }}</td>
<td>{{ $data->role }}</td>
<td>{{ $data->status }}</td>
<td>
<a href="{{ route('admin.auseredit',$data->id)}}" class="btn btn-primary">Edit</a>
</td>
<td>
@csrf
@method('DELETE')
<button class="btn btn-danger" type="submit">Delete</button>
</td>
</tr>
</tbody>
@endforeach
输出应该是一个表,列出数据库中用户表的内容。但我收到未定义的变量错误。
答案 0 :(得分:1)
您应该尝试以下操作:
控制器:
public function index()
{
$userdata = EditUserModel::all()->paginate(5);
$page = array('i'=>(request()->input('page', 1) - 1) * 5);
return view('admin.userman',compact('userdata','page'));
}
路线:
public function index()
{
$userdata = EditUserModel::all()->paginate(5);
$i = (request()->input('page', 1) - 1) * 5;
return view('admin.userman',compact('userdata','i'));
}
型号:
Route::resource('admin.userman', 'EditUserController');
查看:
public class EditUserModel extends Model
{
public $table = "users";
protected $fillable = [
'id',
'name',
'email',
'role',
'password'
];
}
答案 1 :(得分:0)
uint[] retValuesUint = retValues.Select(v => Convert.ToUInt32(v)).ToArray();