"Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP)" in Laravel

10.4k Views Asked by At

When I am trying to update the file then getting error like:

Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of 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

There are 2 best solutions below

7
oreopot On BEST ANSWER

few ways in which you could retrieve variables from $request are shown below:

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

Therefore, for your code to execute correctly.

replace your code:

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

with the following:

$staff->name=$request->name;
$staff->designation=$request->designation;
$staff->ordering=$request->ordering;
0
user15347851 On

Use of undefined constant ‘content’ - assumed '‘content’' (this will throw an Error in a future version of PHP) (View: C:\wamp64\www\amadotester\resources\views\welcome.blade.php)