0

I need to change the value of columns from "0" to "1" after click on the Validate Button in my Application.

The column is saved as "0" by default.

I need to find the right ID of the invoice and update this value. So I tried this code, but my update function is not working.

In view: (Each button got the ID of my invoice)

<form action="{{route('Invoice.update', ['id' => $in->id])}}" method="post">
    {{method_field('patch')}}
    {{csrf_field()}}
    <input type="hidden" name="catid" id="catid" >
    <button type="submit"  data-catid="{{$in->id}}"></button>
</form>

Controller: (Find the Id invoice from value f input)

public function update(Request $request, $id)
{
    $invoice = Invoice::findOrFail($request->catid);
    $invoice->validate = 1;
    $invoice->save();

    return back();    
}

route:

Route::resource('Invoice','ValidateController');

Errors:

  • No query results for model [App\Invoice].

Edited Thanks...

2 Answers 2

2

Because you are using Route::resource('Invoces', 'ValidateController), the route to update your Invoice must provide an ID of the invoice which you whan to update and the update method in your controller must look like this

public function update(Request $request, $id){
    // here goes the code to update the invode
}

You are passing test as value of the ID which the invoice.update route expect.

<form action="{{route('Invoice.update', ['id' => $in->id]}}" method="post">

If you want the route behave the way you specifie you make create a custom route for invode.update. For that you must except the update when you are registering the invoce resource and define another route for the update after

Route::match(['put', 'patch'], '/invoce/update', 'ValidationController@update');
Route::resource('Invoce', 'ValidationController')->except(['update'])
Sign up to request clarification or add additional context in comments.

8 Comments

Hello sir, thank you for ur attention, when i add update with ur response, i got now the id, but i have the error : No query results for model [App\Invoice].
That means there isn't any Invoice with correspond to the ID that you specify
It is sir, they wrote me an ID that exist in my database
Is the ID that you get from the request the same as which is in your database? verify the value of the ID. If It's the right ID it can't return that error. The error which you get means eloquent haven't found any invoice with that id
Yes, the request return : localhost:8000/Invoice/59 And i have an invoice with the id=59
|
0

Are you sure that

My code can't find the invoice ID (catid)

?

You have invalid form action {{route('Invoice.update', 'test')}}. Remove test property - {{route('Invoice.update')}}

And I advise use lowercase in the route names: {{route('invoice.update')}} and Route::resource('invoice', 'ValidateController');

1 Comment

Hello sir, thank you for ur attention. When i remove 'test' i got error message: Missing required parameter

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.