I try to change value of my column in users table with x-editable
and I get 419
error on network.
here is my CONTROLLER
public function changeprimaryaddress(Request $request){
try {
$id = $request->input('pk');
$field = $request->input('name');
$value = $request->input('value');
$user = User::findOrFail($id);
$user->{$field} = $value;
$user->save();
} catch (Exception $e) {
return response($e->getMessage(), 400);
}
my ROUTE
Route::post('/changeprimaryaddress','UserController@changeprimaryaddress')->name('changeprimaryaddress');
my HTML
code
<a href="#"
class="change"
data-type="select"
data-name="address_id"
data-pk="{{ $user->id }}"
data-value="{{ $user->address_id }}"
data-title="Select New Primary Address"
data-url="{{ route('changeprimaryaddress') }}">Change</a>
my JAVASCRIPT
<script type="text/javascript">
$(function() {
$('.change').editable({
source: [
@foreach($addresses as $address)
{ value: '{{ $address->id }}', text: '{{ $address->address }} - {{$address->city->name}}, {{$address->state->name}}, {{$address->country->name}}, {{$address->postalcode}}' }
@unless ($loop->last)
,
@endunless
@endforeach
]
});
});
</script>
If you like to see the process and errors i provided small video you can see.
any idea why is that?
thanks to @SagarGautam. I added
$.ajaxSetup({
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }
});
its working now.