Saturday, March 4, 2017

Laravel Plucking 5.4 error variable undefined

enter image description hereError churchdetails is not defined:

This is the pastorController

   public function index()
{

    $pastors = Pastor::all();
    $churchdetails = Church::all();->pluck('church_name','church_address')
    return view('addpastor')->withpastors($pastors)->withchurchdetails($churchdetails);
}   

public function create()
{
   return view('addpastor');
}

public function store(Request $request)
{
  //validation
    $this->validate($request, [
        'pastor_name' => 'required|max:100',
    ]);

    $pastors = New Pastor;
    $pastors->pastor_name = $request->pastor_name;

    $pastors->save();

    return redirect()->back();
}

This is the view

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Add Church</div>
                <div class="panel-body">
                    {!! Form::open(['route' => 'pastor.store']) !!}
                        {!!  Form::label('churches_id', 'Church Details:', null, array('class' => 'col-md-4 control-label')) !!}

                        {!!  Form::select('churches_id', $churchdetails, null, array('class'=>'form-control', 'style' => 'height:34px', 'required' => ''))!!}


                    <div class="form-group">
                        {!! Form::label('pastor_name', 'Pastor Name:') !!}
                        {!! Form::text('pastor_name', null, array('class' => 'form-control', 'required' => '', 'maxlength' => '100')) !!}


                    {!! Form::submit('Save Church', array('class' => 'btn btn-primary', 'style' => 'margin-top: 20px')) !!}
                    {!! Form::close() !!}
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

@endsection

This is the route

Route::resource('pastor', 'pastorController');
Route::get('pastordetails', 'pastorController@index');

the churchdetails variable is not defined. What did I miss do to? Pls help

and I have already created the relationship between church and pastor

  public function churches(){
        return $this->belongsToMany('App\Church');

   }
   public function pastors (){
        return $this->belongsToMany('App\Pastor');

   }



via Lois Arce

Advertisement