I'm trying to do a simple select summoning data from method pluck.
I tried to do dd($var) in the controller and the x380 data entries are receiving correctly.
Then the next error appears:
Undefined variable: valor (View: C:\laragon\www\envio-curriculum\resources\views\enviar_curriculum.blade.php)
$valor is undefined
Make the variable optional in the blade template. Replace {{ $valor }} with {{ $valor ?? '' }}
If I do this I can see the blade without errors, but in the select appears x380 void data put what I put in the option section.
What am I missing?
EnviarCurriculumController.php
namespace App\Http\Controllers\enviarCurriculum;
use App\EnviarCurriculum;
use App\Configuracion;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests\StoreEnviarCurriculumPost;
class EnviarCurriculumController extends Controller
{
public function create()
{
$configuraciones = Configuracion::pluck('ID', 'variable', 'valor', 'valor_numerico', 'tabla', 'texto_largo', 'observacion');
return view('enviar_curriculum', ['EnviarCurriculum' => new EnviarCurriculum(), 'configuraciones' => $configuraciones]);
}
public function store(StoreEnviarCurriculumPost $request)
{
EnviarCurriculum::create($request->validated());
return back()->with('status', '¡Curriculum creado con éxito!');
}
}
Configuracion.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Configuracion extends Model
{
protected $table = 'configuracion';
protected $primaryKey = 'ID';
protected $fillable = [
'variable',
'valor',
'valor_numerico',
'tabla',
'texto_largo',
'observacion'
];
}
enviar_curriculum.blade.php
<select name="titulacion" id="titulacion">
<option disabled selected value="">* Titulación mas reciente</option>
@foreach ($configuraciones as $configuracion)
<option> {{ $valor }}</option>
@endforeach
</select>
My Answer:
In your blade file, you are trying to access the variable $valor which is not defined in your controller. Instead, you should be accessing the values from the $configuraciones variable that you passed to the view.
You should update your blade file to access the values from the $configuraciones variable like this:
html
This way, you will be able to display the values from the $configuraciones variable in your select dropdown.
Rate this post
4 of 5 based on 4117 votesComments