Condition If in sight, laravel

1

Good, I have a list of students in a view in which I can place observations. My query is how to create an "if" to show me the "add observation" only if you do not have any in the database and in case you already have an observation do not show the "add observation"

These are the fields in the database:

public function up()
{
    Schema::create('conductas', function (Blueprint $table) {
        $table->increments('id');
        $table->enum('tipo',['Positiva','Negativa']);
        $table->string('descripcion');
        $table->date('fecha');

        $table->integer('id_alumno')->unsigned();
        $table->foreign('id_alumno')->references('id')->on('alumnos');

        $table->integer('id_asignatura')->unsigned();
        $table->foreign('id_asignatura')->references('id')->on('asignaturas');

        $table->timestamps();
    });
}

And my view:

@section('content')
	        	
	 <strong>Asignatura :   </strong>   <a>  {{$asignatura->nombre}}</a><br>
	 <strong>Curso : </strong> <a>{{$asignatura->curso->nombre." / ".$asignatura->curso->tipo}}</a><br>
	 <strong>Periodo :	  </strong> <a>{{$asignatura->periodo." - ".$asignatura->created_at->year}}</a><br>
	 <strong>Horario : 	  </strong> <a>{{$asignatura->horario}}</a><br><br>
	
	 
	<table class="table table-bordered">
		<tr>
			<th>N°</th>
			<th>Rut</th>
			<th>Nombres</th>
			<th>Apellidos</th>
			<th>Correo</th>
			<th>Información</th>
			<th>Anotaciones</th>	
		</tr>

			@foreach ($alumnos as $alu)
				<tr>
					<td>{{ ++$i }}</td>
					<td>{{ $alu->rut }}</td>
					<td>{{ $alu->nombre}}</td>
					<td>{{ $alu->apellido_paterno." ".$alu->apellido_materno}}</td>
					<td>{{ $alu->email}}</td>

					<td><a href="{{route('alumnos.show', $alu->id)}}" class="btn btn-info" ><span class="fa fa-eye" aria-hidden="true"></span></a><br><br></td>
					
					<td><a href="{{URL('datos-profesor/veranotacion', $alu->id)}}" class="btn btn-warning" ><span class="fa fa-file-text" aria-hidden="true"> </span></a>
					@if({{???}})
					<a href="{{URL('agregar/anotacion', array($alu->id, $asignatura->id ))}}" class="btn btn-danger" ><span class="fa fa-plus-square" aria-hidden="true"></span></a></td>

				</tr>
			@endforeach

	</table>

@endsection

Thank you in advance.

    
asked by Edgardo Escobar 08.03.2017 в 22:54
source

1 answer

0

It is still unclear how you get the observations of the students. But the answer would be:

@if (count($alu->observaciones) > 0)
    <a href="{{URL('agregar/anotacion', array($alu->id, $asignatura->id ))}}" class="btn btn-danger" ><span class="fa fa-plus-square" aria-hidden="true"></span></a></td>
@endif

The most logical thing would be to add a table "observations" (plural observation), I would give you the possibility to add more than 1 observation and this code would not make sense. but everything depends on your implementation

public function observaciones()
{
    return $this->hasMany('App\Observacion');
}
    
answered by 09.03.2017 / 00:43
source