Laravel中的“使用未定义的常量名称-假定为'名称'(这将在以后的PHP版本中引发错误)”

时间:2019-05-20 06:50:02

标签: laravel-5 laravel-5.1

当我尝试更新文件时,出现如下错误:

  

使用未定义的常量名称-假定为“名称”(在将来的PHP版本中将引发错误)

public function update(Request $request, $id)
{
    $this->validate($request,[
        'name'=>'required',
        'designation'=>'required',
        'contact_ph'=>'required',
        'contact_email'=>'required',
        'featured'=>'mimes:jpeg,pdf,docx,png:5000',
    ]);

    $staff=Staff::find($id);

    if($request->hasFile('featured'))
    {
        $featured=$request->featured;
        $featured_new_name =time() .$featured->getClientOriginalName();
        $featured->move('uploads/srcpost', $featured_new_name);
        $staff->featured='uploads/srcposts/'. $featured_new_name;
    }

    $staff->name=$request=name;
    $staff->designation=$request=designation;
    $staff->ordering=$request=ordering;

    $staff->save();

    return redirect()->back();
}

2 个答案:

答案 0 :(得分:1)

$request检索变量的几种方法如下所示:

$request->name;
$request->get('name');
$request->input('name');

因此,您的代码可以正确执行。

替换您的代码:

 $staff->name=$request=name;
 $staff->designation=$request=designation;
 $staff->ordering=$request=ordering;

具有以下内容:

$staff->name=$request->name;
$staff->designation=$request->designation;
$staff->ordering=$request->ordering;

答案 1 :(得分:0)

使用未定义的常量 'content' - 假定为 ''content''(这将在 PHP 的未来版本中引发错误)(查看:C:\wamp64\www\amadotester\resources\views\welcome.blade。 php)