Tuesday, February 20, 2018

How To Solve This Trying to get property of non-object Error In Laravel - development

How To Solve This Trying to get property of non-object Error In Laravel

I’m creating a web site. And I have created a registration page. I want to update my details.

But, It gives me this error and I have also uploaded a picture of errors below. –
Error Picture

ErrorException (E_ERROR) Trying to get property of non-object (View:
D:wamp64wwwFinalProjectresourcesviewsAdminUpdate.blade.php)

I used dd($edd); and it gave me correct details. But, when I try with below codes it gives me that above error.

How can I Fix this ??

Here is my AdminPanel.blade.php

<table class="table table-bordered">

<tr>
<td> Name </td>
</tr>


@foreach($data as $value )
<tr>
<td>  </td>
<td> <a href="edit/"><input type="submit" name="update" value="Update" class="btn-primary"></a> </td>
</tr>
@endforeach
</table>

Here is my AdminPanelController.php

public function edit($id)
{
$edd = User::find($id);
//dd($edd);
      return view('AdminUpdate', ['edd' => $edd]);

}

    public function adminedit($id, Request $request, User $user)
{
    // Add Validation

    $users = $user->find($id);
    $users->username = $request->get('username');
    $users->email = $request->get('email');
    $users->save();

    return redirect()->back();
}

Here is my AdminUpdate.blade.php

<form action="edit/" method="post" enctype="multipart/form-data">

    
    

  <div class="form-group">
    <label>Username : *</label>
    <input type="text" class="form-control" name="username" value="" placeholder="Enter Your Username" required>
  </div>

    <div class="form-group">
    <label>Email : *</label>
    <input type="email" class="form-control" name="email" value="" placeholder="Enter Your Username" required>
  </div>

  <div class="form-group">
    <label>Password : *</label>
    <input type="password" class="form-control" name="password" value="" placeholder="Enter Your Password" required>
  </div>

  <div class="form-group">
    <label>Upload Profile Picture :</label>
    <input type="file" class="form-control-file" name="file_img" aria-describedby="fileHelp">
    <small id="fileHelp" class="form-text text-muted">If U Want , U Can Skip Upload A Profile Picture</small>
  </div>

  <input type="submit" class="btn btn-primary" value="Update User">
                    </form>

Here are my Routes.

Route::get('/edit/{id}', 'AdminPanelController@edit');

Route::post('/edit/{id}', 'AdminPanelController@adminedit');



from Laravel Questions and Answers https://laravelquestions.com/php/how-to-solve-this-trying-to-get-property-of-non-object-error-in-laravel/
via Lzo Media

No comments:

Post a Comment