skip to Main Content

this is the controller code
and this is the route
and this is the blade code:

<div class="container mt-5 mb-5 w-25" >
  <div class="card">
    <div class="card-header">
      <p class="fs-1">Update Members</p>
    </div>
    <div class="card-body">
      <form class="row g-3" action="/update" method="POST">
        @csrf
        <div class="col-12">
          <label for="id" class="form-label">Id</label>
          <input type="hidden" value="{{$data['id']}}" class="form-control "  id="id">
        </div>
        <div class="col-12">
          <label for="name" class="form-label">Name</label>
          <input type="text" class="form-control" value="{{$data['Name']}}"  id="name">
        </div>
        <div class="col-12">
          <label for="email" class="form-label">Email</label>
          <input type="text" class="form-control" value="{{$data['Email']}}" id="email">
        </div>
        <div class="col-12">
          <label for="address" class="form-label">Address</label>
          <input type="text" class="form-control" value="{{$data['Address']}}" id="address">
        </div>
        <div class="col-12">
          <label for="phone" class="form-label">Phone</label>
          <input type="text" class="form-control" value="{{$data['Phone']}}" id="phone">
        </div>
        
        <div class="col-12">
          <button type="submit" class="btn btn-primary">Update</button>
          <hr class="border border-primary border-3 opacity-75">
        </div>
      </form>
      
    </div>
  </div> 
</div>

I am trying to save this four columns in the database name email address and phone
then this error happened.
please answer me quickly if you can?

I am trying to save data in these columns

2

Answers


  1. One possibility is that, in the controller, $data is null. You can make the code fail by changing "find" to "findOrFail". The code will return a NotFoundException. Then you can investigate why $data is null.

    Read https://laravel.com/docs/9.x/eloquent#not-found-exceptions.

    Login or Signup to reply.
  2. the problem is probably in your update function it should be like this:

    function update(Request $req){
    $data = Member::find($req->id);
    
    $data->Name = $req->Name;
    $data->Email= $req->Email;
    $data->Address = $req->Address;
    $data->Phone = $req->Phone;
    $data->save();
    
    return redirect()->input();
    }
    

    in your update function you have changed the upper case to a lower case which will cause the Attempt to assign property "name" on null Error

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search