1

I am trying to get values from selected row when button "edit" is clicked. I get row id in controller via button

value="{{ $record->id }}"

but I can not get name from

<td id="name" contenteditable="true">{{ $record->name }}</td>

I know that I do not have name so I writed jquery script:

$('#edit').on('click', function () {
    var name = $(this).closest('tr').find('#name').text();
});

and when I write window.alert(name); I see selected row value. So how to send it to controller. Any suggestions?

1 Answer 1

1

Here is the easiest way to do it: First you declare your route in the route file:

Route::get('somename/{id}/{name}','your_controller@your_method')->name('route_name');

Second in your view call the route in an side href per example:

<a href="{{route('route_name',['id'=>$record->id,'name'=>$record->name] )}}"

Make sure the route_name in the href matches the route_name in the route.

Third and last retrieve the id from the controller as so:

public function your_method($id,$name){
//you can access $id and $name now
}
Sign up to request clarification or add additional context in comments.

3 Comments

I can get id in my controller but not name. I have button with value id. I need to get name from table row.
check answer to pass multiple values
But I dont need a link or values in it. I have table with rows and in each row i print name. Now I want to edit it and need to get name in controller when edit button is clicked. There is problem that in table I can not write name="name" only id

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.