In my Laravel 5.5 project use an x-editable popup field to do an on-page edit to a field. The user clicks the value and an editable popup shows, committing the change to the database when they confirm (enter or click checkmark icon). This was working great, but then I changed my route code to add a parameter to the page URL to load one version of the page or the other depending on the parameter used. This works for the page selection, but has broken all instances of x-editable in the loaded page. They now break with the following error (just first salient first part shown as the error dump is 200 lines)
Edit Amount
212000.00
{
"message": "",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException",
"file": "C:\\xampp\\htdocs\\DS_dev_01\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php",
"line": 255,
"trace": [
{
"file": "C:\\xampp\\htdocs\\DS_dev_01\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php",
"line": 242,
"function": "methodNotAllowed",
"class": "Illuminate\\Routing\\RouteCollection",
"type": "->"
},
...
The x-editable code in my view page is:
<a href="#" class="assetName" data-type="text" data-name="split_amount" data-url="update-investment-row" data-pk="" data-title="Edit Amount" data-value="">$</a>
My (web.php) route that handles the ajax call from this popup is:
Route::post('atcv-split-scenario/update-investment-row', 'InvestmentLineSplitController@updateRow')->middleware('auth');
The controller (InvestmentLineSplitController) code that processes the update_row call:
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\investment_line_split $investment_line_split
* @return \Illuminate\Http\Response
*/
public function updateRow(Request $request, investment_line_split $investment_line_split)
{
$pk = $request->input('pk');
$splitRecord = $investment_line_split::findOrFail($pk);
// get column name
$col = $request->input('name');
// get new value
$value = $request->input('value');
$splitRecord->$col = $value;
$splitRecord->save();
return \Response::json(array('status' => 1));
}
The URL that calls that page is http://ds_dev_01.test:8080/atcv-split-scenario/Joe%20vs%20Anne/s
where the last "S" parameter is tripping this up. Before I added the last parameter (S or M determines which of two versions of the page gets loaded) the x-editable worked fine, so somehow that last parameter is the issue, but I can't see where my code or route are incorrect and how that would effect it. All the above code works fine with no last parameter.
Here's the javascript behind the scenes:
$(document).ready(function() {
$.fn.editable.defaults.mode = 'popup';
$.fn.editable.defaults.send = "always";
$.fn.editable.defaults.params = function (params)
{
params._token = $("#_token").data("token");
return params;
};
$.fn.editable.defaults.success = function(response, newValue)
{
//if(!response.success) return response.msg;
window.location.reload();
};
$('.assetName').editable({
ajaxOptions: {
dataType: 'json',
type: 'post'
}
});
});
The error hints at the wrong method being used, but I know it's correct as it works on a page without the added URL parameter. I need the parameter to determine which page loads, but how can I make the x-editable work with that (and why doesn't it)?
Any thoughts or suggestions?
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2ZL6SV7
via IFTTT
Aucun commentaire:
Enregistrer un commentaire