I m using x-editable in laravel 5.2. I want to store the text of the corresponding value from data-source. I m only able to store the value in database.
my view:
<label>Course:</label><a href="#" id="course" data-name="course" data-type="select" data-value="" data-pk="{{Auth::user()->id}}" data-source="{1: 'B.tech', 2: 'M.tech'}" data-title="course" data-url="{{route('course')}}"></a>
controller:
public function course(Request $request)
{
$account = new Account();
$name = $request->get('name');
$value = $request->get('value');
$request->user()->accounts()->update([$name => $value]);
return redirect()->back();
}
X-Editable by default creates the select
with the source object keys as option values and the source values as the options display text. Naturally, when the request is sent, the values (1 or 2 in your case) are sent instead of the texts.
But if the source is an array, the value will be the same as the text. So, you can just do
<a ... data-type="select" data-source="['B.tech', 'M.tech']"></a>
If you can't or don't want to change that original source of data, instead of setting the source as attribute you can do it when you initialize the component:
$('#YOUR_ELEMENT').editable({
// ...
source: function () {
var items = {1: 'B.tech', 2: 'M.tech'};
return Object.keys(items).map(function(x) {return items[x];});
},
// ...
});