I'm trying something half crazy. The use case is that every 2 years the Board of Directors changes, so this year it will change to the XXXVII Council (It is currently in the XXXVI). It made me absurd to create a table just to save the number of advice then it occurred to me to save the number in a variable created in the controller and edit it with x-editable. Everything is fine except that it does not save the variable. Here is my code:
Controller Code
//Declaro la variable
protected $consejo;
// Inicializo la viariable para mandarla a la vista
public function editDirectors()
{
$numConsejo = $this->consejo;
return view('board.edit_directors', compact('numConsejo'));
}
//Se supone que guardo la variable
public function uploadNumber(Request $request)
{
$this->consejo = $request->value;
$numConsejo = $this->consejo;
return $numConsejo;
}
Code in the template
<a href="#" id="num-consejo" data-type="text"
data-pk="1"
data-url="{{url('/consejo-directivo/editar/numero-consejo')}}"
data-value="{{$numConsejo}}"
data-name="numConsejo"
data-title="Número de Consejo Directivo">{{$numConsejo}}</a>
Consejo Directivo</h3>
I initialize the x-editable
//Se inicializa el x-editable para modificar el número del comité
$('#num-consejo').editable({
error: function(response, newValue)
{
if(response.status === 500) {
return 'Parece que hubo un error al guardar. Favor de reportarlo a: [email protected]';
} else {
return 'Parece que hubo un error al guardar. Favor de reportarlo a: [email protected]';
}
}
});
And the route
Route::put('/consejo-directivo/editar/numero-consejo' , 'DirectorController@uploadNumber');//Ruta para guardar el número de consejo
I am more than sure that I am saving the variable but I can not find any solution because I already debug the console and the Request arrives at the controller and makes the return with the value that I entered in the x-editable but when I gave it F5 it was not saved and when I do a var_dump () or dd () in the editDirectors () method I get that the $ advice variable is null.
I am grateful for the help and attention if you came to read up to here: 3
Modifications
I made a file in the config folder to store the value there (config / board.php) and added the following code:
return [
'director' => [
'number' => 'XXXVI'
]
];
Often I modified the controller code:
//Aquí traigo el valor de config/board.php y lo mando al template, funciona :D
public function editDirectors()
{
$numConsejo = Config::get('board.director.number');
return view('board.edit_directors', compact('directors', 'numConsejo'));
}
//Aquí se supone que guardo la variable en el archivo config/board.php pero no guarda :(
public function uploadNumber(Request $request)
{
$numConsejo = $request->value;
Config::set('board.director.number', $numConsejo);
dd(Config::get('board.director.number'));
//return $numConsejo;
}
I had to run the command:
php artisan config:cache
This is so that the config / board.php file could be displayed but it seems that each time the value of that file is modified, I need to run that command.
Any ideas? I would greatly appreciate the help: 3