简体   繁体   English

ErrorException (E_ERROR) 未定义变量:年龄(视图:/home/....profile.blade.php)

[英]ErrorException (E_ERROR) Undefined variable: age (View: /home/....profile.blade.php)

I am getting an error on a recycled code which works perfectly fine in another section of the app..我在回收代码上遇到错误,该代码在应用程序的另一部分运行良好。

Controller :控制器 :

public function edit($id)
{
    $user = User::findOrFail($id);
    $gender = Gender::pluck('name', 'id')->all();
    $age = Age::pluck('group', 'id')->all();
    return view('profile', compact('user', 'gender', 'age'));
}

View :看法 :

<div class="form-group">
    {!! Form::label('age_id', 'Age Group: ') !!}
    {!! Form::select('age_id', $age, null, ['class'=>'form-control']) !!}
</div>

Request :要求 :

public function authorize()
{
    return Auth::check();
}

public function rules()
{
    return [
        // 'name'      =>  'required|string|min:4|max:40',
        // 'email'     =>  'required|string|email|min:8|max:40|unique:users',
        // 'photo_id'  =>  'required',
        // 'gender_id' =>  'required',
        // 'age_id'    =>  'required',
        // 'password'  =>  'required|string|min:8|max:16'
    ];
}

In the "compact()" function, you are passing 3 variables as a string:在“compact()”函数中,您将 3 个变量作为字符串传递:

       return view('profile', compact('user', 'gender', 'age'));

You have to pass them inside an array:您必须将它们传递到数组中:

       return view('profile', compact(['user', 'gender', 'age']));

I will have to see the Model if this doesn't fix the bug, but for now is the only thing that I can see.如果这不能修复错误,我将不得不查看模型,但现在是我唯一能看到的东西。 Let us know the results.让我们知道结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ErrorException (E_ERROR) 未定义变量:pages - ErrorException (E_ERROR) Undefined variable: pages Laravel-ErrorException(E_ERROR)未定义的变量 - Laravel - ErrorException (E_ERROR) Undefined variable 未定义变量:posts(查看:C:\Users\BWB\Documents\Laravel\restravels\resources\views\profile.blade.php) - Undefined variable: posts (View: C:\Users\BWB\Documents\Laravel\restravels\resources\views\profile.blade.php) ErrorException (E_ERROR) 使用未定义的常量 yonetim - 假定为 &#39;yonetim&#39;(这将在 PHP 的未来版本中引发错误) - ErrorException (E_ERROR) Use of undefined constant yonetim - assumed 'yonetim' (this will throw an Error in a future version of PHP) Laravel 6 ErrorException 未定义变量:用户(…home.blade.php) - Laravel 6 ErrorException Undefined variable: user (…home.blade.php) ErrorException(E_ERROR)从空值创建默认对象(视图:D:\\ - ErrorException (E_ERROR) Creating default object from empty value (View: D:\ ErrorException 未定义变量:联系人(视图:MyCrud/resources/views/contacts/index.blade.php) - ErrorException Undefined variable: contacts (View:MyCrud/resources/views/contacts/index.blade.php) Laravel:ErrorException (E_ERROR) 在 null 上调用成员 function getAvatar() - Laravel : ErrorException (E_ERROR) Call to a member function getAvatar() on null ErrorException(E_ERROR)找不到类&#39;app \\ Project&#39; - ErrorException (E_ERROR) Class 'app\Project' not found 未定义变量:在 home.blade.php 中发布 - Undefined variable: post in home.blade.php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM