Undefined variable: institutions (View:

0

Expensive,

I have a very annoying and persistent error.

Undefined variable: institutions (View:

I have looked several times and I do not know why the data is not passed to the form.

Controller


namespace App\Http\Controllers;

use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Http\Requests\OcorrenciaRequest; use Carbon\Carbon;

use App\Ocorrencia;

class OcorrenciasController extends Controller { //public function __construct() //{

//}

/**
 * Display a listing of the resource.
 *
 * @return Response
 */
public function index()
{
    //variavel #ocorrencias amarzena o comteudo do model/bd (Ocorrencia) e realiza a paginação      
    $ocorrencias = Ocorrencia::paginate(5);
    //$ocorrencias = Ocorrencia::all();

    //Compact na variavel ocorrencias (Array)
    return view('ocorrencias.index', compact('ocorrencias'));
    //dd(hora_final, hora_inicial)

}

/**
 * Show the form for creating a new resource.
 *
 * @return Response
 */
public function create()
{
    //retorna a função create na view
    return view('ocorrencias.create');
    //return view('ocorrencias.create')->with('institutions',Institution::lists('name','id'));

}

/**
 * Store a newly created resource in storage.
 *
 * @param  Request  $request
 * @return Response
 */
//
public function store(OcorrenciaRequest $request)
{
    $ocorrencia = Ocorrencia::create($request->all());

    $ocorrencia = $this->setOcorrenciaRelations($ocorrencia, $request);        
    $ocorrencia->save();

    return redirect()->route('ocorrencia.index');
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return Response
 */

public function show(Ocorrencia $ocorrencia)
{
    return view('ocorrencias.show', compact('ocorrencia'));
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return Response
 */

public function edit(Ocorrencia $ocorrencia)
{
    //Compact na variavel ocorrencia.
    return view('ocorrencias.edit', compact('ocorrencia'));
}

/**
 * Update the specified resource in storage.
 *
 * @param  Request  $request
 * @param  int  $id
 * @return Response
 */

public function update(OcorrenciaRequest $request, Ocorrencia $ocorrencia)
{
    $ocorrencia->update($request->all());

    $ocorrencia = $this->setOcorrenciaRelations($ocorrencia, $request);
    $ocorrencia->save();

    return redirect()->route('ocorrencia.index');
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return Response
 */

public function destroy(Ocorrencia $ocorrencia)
{
    $ocorrencia->delete();

    return redirect()->route('ocorrencia.index');
}

private function setOcorrenciaRelations(Ocorrencia $ocorrencia, Request $request)
{
    $institution = Institution::findOrFail($request->institution_id);
    $ocorrencia->institution()->associate($institution);
    $aplication = Aplication::findOrFail($request->aplication_id);
    $ocorrencia->aplication()->associate($aplication);
    $ocorrencia->causes()->sync($request->causes_list);
    //$user = User::findOrFail($request->user_id);
    //$ocorrencia->user()->associate($user);

    return $ocorrencia;


}

}

Form

    {!! Form :: label ('start_date', 'Start Date') !!}     {!! Form :: date ('start_date', null, ['class' => 'form-control', 'placeholder' => 'Start Date'])     {!! Form :: label ('start_date', 'Start Time') !!}     {!! Form :: time ('data_initial', null, ['class' => 'form-control', 'placeholder' => 'Start Time'])     {!! Form :: label ('data_final', 'End Date') !!}     {!! Form :: date ('data_final', null, ['class' => 'form-control', 'placeholder' => 'Final Data'])     {!! Form :: label ('endtime', 'End Time') !!}     {!! Form :: time ('final_time', null, ['class' => 'form-control', 'placeholder' => 'End Time'])     {!! Form :: label ('institution_id', 'Institution') !!}     {!! Form :: select ('institution_id', $ institutions, null, ['class' => 'form-control', 'placeholder' => 'Select an Institution ...'     {!! Form :: label ('logged in', 'Logados') !!}     {!! Form :: text ('logados', null, ['class' => 'form-control', 'placeholder' => 'Logs'])     {!! Form :: label ('institution_id', 'Institution') !!}     {!! Form :: select ('institution_id', $ institutions, null, ['class' => 'form-control', 'placeholder' => 'Select an Institution ...'     {!! Form :: label ('observation', 'Occurrence') !!}     {!! Form :: textarea ('observation', null, ['class' => 'form-control', 'placeholder' => 'Occurrence ...']))}

{!! Form :: submit ('Send', ['class' => 'btn btn-default']) !!}

Model

App namespace;

use Illuminate \ Database \ Eloquent \ Model;

class Occurrence extends Model {

// protected $ table="occurrences";

protected $ fillable = [

'data_inicial', 'hora_inicial', 'data_final', 'hora_final', 'logados', 'observacao' ]; public function institution() { return $this->belongsTo('App\Institution'); } public function causes() { return $this->belongsToMany('App\Cause'); } public function aplication() { return $this->belongsTo('App\Aplication'); } /*public function user() { return $this->belongsToMany('App\User'); }*/ // Eloquent Accessor // Cria uma nova propriedade dinamica // Convenção: get + CampoEmCamelCase + Attribute // Será convertido em $this->campo_em_camel_case public function getCausesListAttribute() { return $this->causes->lists('id')->toArray(); }

}

    
asked by anonymous 12.10.2017 / 00:41

0 answers