Paulius Jasiulis
Paulius Jasiulis

Reputation: 53

Laravel send value from table row to controller

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?

Upvotes: 1

Views: 1867

Answers (1)

Sletheren
Sletheren

Reputation: 2478

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
}

Upvotes: 1

Related Questions