Problems with a view, with create () and store () methods

2

I have a Controller to add an "Annotation" to a student, which receives "student_id", "id_asignatura" and "id_profesor", but I have problems in the view, since it only shows me the "id" in the fields and even though I change parameters it does not work for me.

This is the Form:

{{ Form::open(array('url' => 'agregar/anotacion','method'=>'POST')) }}
		<div class="row">
			<div class="col-xs-6 col-sm-6 col-md-6">

				<div class="form-group">
                    {!! Form::label('id_alumno', 'Alumno') !!}
                    {!! Form::text('id_alumno', $alumno->id, array('class' => 'form-control')) !!}
                </div>

                <div class="form-group">
                    {!! Form::label('id_asignatura', 'Asignatura') !!}
                    {!! Form::text('id_asignatura', $asignatura->id, array('class' => 'form-control')) !!}
                </div>

                 <div class="form-group">
	                {!! Form::label('tipo','Tipo')!!}
	                {!! Form::select('tipo', ['' => 'Seleccionar...','Positiva' => 'Positiva', 'Negativa' => 'Negativa'], null, ['class' => 'form-control']) !!}
	            </div>

	            <div class="form-group">
	                {!! Form::label('descripcion','Descripcion')!!}
	                {!! Form::textarea('descripcion', null,['class' => 'form-control textarea-descripcion']) !!}
	            </div>

				<button type="submit" class="btn btn-primary">Registrar</button>    
				<a class="btn btn-danger" href="{{URL('showalumnosasignatura', $asignatura->id)}}">Cancelar</a>   	
	        </div>
		</div>
	{{ Form::close() }}

When I make changes to the variable, for example $ student- > name and $ asignatura_nombre, it shows me the name of the student and subject, but when registering the annotation it does not receive the "ids" and the error data. Does anyone know how I could solve this? I want you to show me the Rut and the Code of the subject in the field and in a "disabled" way. When I put disabled, I do not catch the "ids" of both.

This is my Controller:

public function agregarAnotacion($id, $idasi)
{   
    $alumno = Alumno::find($id);
    $asignatura = Asignatura::find($idasi);
    return view('agregar/anotacion')->with('alumno',$alumno)->with('asignatura',$asignatura);
}

public function guardarAnotacion(Request $request)
{
    $conducta = new Conducta($request->all());

    $conducta->id_profesor = auth('profesor')->user()->id;

    $conducta->fecha = Carbon::now();
    $conducta->save();

    flash('Anotacion agregada exitosamente!','success');
    return redirect()->route('conductas.index');
}

And my routes:

Route::get('agregar/anotacion/{id}/{idasi}','[email protected]');
Route::post('agregar/anotacion','[email protected]');
    
asked by Edgardo Escobar 08.03.2017 в 15:17
source

1 answer

1

Instead of disabled , which is not sent, you could use the readonly property in the fields. This would be something like:

{!! Form::text('id_alumno', $alumno->id, array(
                                          'class' => 'form-control',
                                          'readonly' => 'readonly'
                                         )) !!}

Additionally, for the text fields that will be readonly, you can display the name associated with the ID and add, in your template, a hidden type input that contains the ID. That way you'll send both to your backend.

{!! Form::hidden('id_alumno', $alumno->id) !!}
{!! Form::text('nombre_alumno', $alumno->nombre, array(
                                          'class' => 'form-control',
                                          'readonly' => 'readonly'
                                         )) !!}
    
answered by 08.03.2017 / 15:29
source