0

I have a CRUD with simple date. But I can't get the update method to work.

This is my controller

public function show(Customer $customer)
{
    return view('customer.show',compact('customer'));

}


public function edit(Customer $customer)
{
    return view('customer.edit', compact('customer'));

}

public function update(CustomerRequest $request, Customer 
$customer,$id)
{
    $customer = Customer::find($id)->update($request->all());

    return redirect()->route('customer.index',compact('customer'));
}

and that is my view

 <form method="POST" action="{{route('customer.update',$customer->id ) }}">
            {{--{{dd($customer)}}--}}
            {{method_field('PUT')}}

                {{ csrf_field() }}

                <div class="form-group">
                    <label for="firstName">Voornaam</label>
                    <input type="text" class="form-control"  name="firstName" value="{{$customer->firstName}}">
                </div>

                <div class="form-group">
                    <label for="lastName">Achternaam</label>
                    <input type="text" class="form-control"  name="lastName" value="{{$customer->lastName}}">
                </div>

                <div class="form-group">
                    <label for="email">Email</label>
                    <input type="email" class="form-control"  name="email" value="{{$customer->email}}">
                </div>

                <div class="form-group">
                    <label for="phone">Telefoonnummer</label>
                    <input type="text" class="form-control"  name="phone" value="{{$customer->phone}}">
                </div>


                <div class="form-group">
                    <button type="submit" class="btn btn-primary">Update</button>
                </div>
            </form>

I can go to the edit page. But, after changing the data nothing change it look like that I miss save somewhere but I don't know, now I get that that error too few arguments to function New Controller ::update () 2 passed and exactly 3 expected.

any help will be appreciated.

1 Answer 1

1

Change:

public function update(CustomerRequest $request, Customer $customer,$id)

To:

public function update(CustomerRequest $request, $id)

Or:

public function update(CustomerRequest $request, Customer $customer)

With the last one you can remove Customer::find($id) and just use $customer

EDIT If you look at the update route: route('customer.update',$customer->id ) you see it only takes 1 argument. The controller expects 2 because one is the request and the other is the ID.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot, i change indeed the update to. public function update(CustomerRequest $request, $id) {$customer = Customer::find($id)->update($request->all()); return redirect()->route('customer.index',compact('customer')); } and now it work just fijn

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.