2017-05-15 7 views
0

イム、ホープ誰かがイムは、間違っているものを指摘することができ、すでに私の見解に私のコントローラから変数を渡すには、いくつかの方法を試してみましたが、ナッシングは動作するようです。Laravel 5未定義の変数コントローラ2ビュー

public function busquedaGet() 
{ 
    return view('frontend.user.busquedaBoxeadores',compact('posts')); 

} 




public function busquedaPost(Request $request, BusquedaRepository $userRepo) 

{ 
    $validator = Validator::make($request->all(), [ 
     'gender' => 'required|not_in:null', 
     'weight' => 'required|not_in:null', 
     'country' => 'required|not_in:null' 
    ]); 


    if ($validator->fails()) { 
     return redirect(route('busquedaPostA'))->withErrors($validator); 
    } 

    $posts=$userRepo->busquedaBoxers($request->all()); 
     //dd($posts); 
    return view('frontend.user.busquedaBoxeadores',compact('posts')); 

} 

ビュー:

@extends('frontend.layouts.app') 

@section('title') 
    {{{ trans('app.contrataBoxeadores') }}} 
@endsection 

    <div class="container"> 
    <div class="row"> 
     <div class="col-md-3 visible-lg"> 
     <div class="side-bar"> 
     </div> 
     </div> 

     <div class="col-md-6"> 
     <div class="updates"> 
     <div class="panel panel-default panel-update mg-top20"> 
      <div class="panel-heading"> 
      <h3 align="center">{{{ trans('app.red') }}} </h3> 
      </div> 
      <div class="panel-body"> 
        {!! Form::open(['url' => route('busquedaPostA')]) !!} 
           <div class="form-group {{ $errors->has('gender') ? ' has-error' : '' }}"> 
            {!! Form::label('gender', trans('app.gender')); !!} 
            {!! Form::select('gender', ['null' => trans(''),'F' => trans('app.female'), 'M' => trans('app.male')], null, ['class' => 'form-control']) !!} 
            @if ($errors->has('gender')) 
             <span class="help-block"> 
              <strong>{{ $errors->first('gender') }}</strong> 
             </span> 
            @endif 
           </div> 
           <div class="form-group {{ $errors->has('weight') ? ' has-error' : '' }}"> 
            {!! Form::label('weight', trans('app.weight')); !!} 
            {!! Form::select('weight', ['null' => trans(''), 
            ' 1' => trans('Mini flyweight'), 
            ' 2' => trans('Fyweight'), 
            ' 3' => trans('Super flyweight'), 
            ' 4' => trans('Bantamweight'), 
            ' 5' => trans('Super bantamweight'), 
            ' 6' => trans('Featherweight'), 
            ' 7' => trans('Super featherweight'), 
            ' 8' => trans('Lightweight'), 
            ' 9' => trans('Super lightweight'), 
            '10' => trans('Welterweight'), 
            '11' => trans('Super welterweight'), 
            '12' => trans('Middleweight'), 
            '13' => trans('Super middleweight'), 
            '14' => trans('Light heavyweight'), 
            '15' => trans('Cruiserweight'), 
            '16' => trans('Heavyweight')], 
            null, ['class' => 'form-control']) !!} 
            @if ($errors->has('country')) 
             <span class="help-block"> 
              <strong>{{ $errors->first('weight') }}</strong> 
             </span> 
            @endif 
           </div> 
           <div class="form-group {{ $errors->has('country') ? ' has-error' : '' }}"> 
            {!! Form::label('country', trans('country.countries')); !!} 
            {!! Form::select('country', ['null' => trans(''), 
            'us' => trans('country.united'), 'bz' => trans('country.brazil'), 'mx' => trans('country.mexico'), 'cl' => trans('country.colombia'),'ar' => trans('country.argentina'), 'ca' => trans('country.canada'), 'pu' => trans('country.peru'), 'vz' => trans('country.venezuela'), 'cl' => trans('country.chile'), 'ec' => trans('country.ecuador'), 'gt' => trans('country.guatemala'), 'cb' => trans('country.cuba'), 'hi' => trans('country.haiti'), 'bl' => trans('country.bolivia'), 'dr' => trans('country.dominican'), 'hnd' => trans('country.honduras'), 'pa' => trans('country.paraguay'), 'nic' => trans('country.nicaragua'),'slv' => trans('country.salvador'), 'cr' => trans('country.costa'), 'pnm' => trans('country.panama'), 'pr' => trans('country.puerto'), 'urg' => trans('country.uruguay'),'jam' => trans('country.jamaica'), 'tt' => trans('country.trinidad'), 'blz' => trans('country.belize'), 'brb' => trans('country.barbados'), 'ot' => trans('country.other')], 
            null, ['class' => 'form-control']) !!} 
            @if ($errors->has('country')) 
             <span class="help-block"> 
              <strong>{{ $errors->first('country') }}</strong> 
             </span> 
            @endif 
           </div> 
           <div class="form-group"> 
           {!! Form::submit(trans('app.buscar'), ['class' => 'btn btn-lg btn-primary btn-block signup-btn']); !!} 
           </div> 
      {!! Form::close() !!} 
      </div>   
     </div> 
     </div> 
     </div> 

    <div class="col-md-3 visible-lg"> 
    <p> Hello, {{ $posts }} </p> 
    </div> 
    </div> 
</div> 

経路

Route::post('/profile/busquedaBoxeadores',['as' => 'busquedaPostA', 'uses' => '[email protected]']); 
    Route::get('/profile/busquedaBoxeadores', ['as' => 'busquedaGetA', 'uses' => '[email protected]']); 

リポジトリ

public function busquedaBoxers(array $data, $source = 'site') 
{ 
$query = DB::table('users') 
     ->join('user_profiles', 'users.id', '=', 'user_profiles.user_id') 
     ->join('boxings', 'users.id', '=', 'boxings.user_id') 
     ->join('countries', 'users.id', '=', 'countries.user_id')   
     ->select('users.name', 'users.username', 'users.id') 
     ->where('boxings.weight_id', '=', $data['weight']) 
     ->where('user_profiles.gender', '=', $data['gender']) 
     ->where('countries.country', '=', $data['country']) 
     ->get(); 

     return $query; 
} 
予め

コントローラで おかげ

+0

エラーの説明を追加 –

+0

正確なエラーメッセージは何ですか? – aynber

+0

未定義の変数:posts(表示:C:\ Users \ Bof3ss37 \ Desktop \ socialwall_v1.0.3 \ resources \ views \ frontend \ user \ busquedaBoxeadores.blade.php) –

答えて

1

busquedaGetbusquedaPostの両方で同じビューを使用していますが、busquedaGetには、compactの変数postsが定義されていません。したがって空の文字列を取得メソッドで使用していない場合は追加できます。

public function busquedaGet() 
{ 
    $posts = []; 
    return view('frontend.user.busquedaBoxeadores',compact('posts')); 
} 

ビューを変更します。あなたは、ブレード内の文字列として記事を表示しようとしている

<p> Hello, 
@foreach($posts as $post) 
    {{ $post->username }} 
@endforeach 
</p> 
+0

おかげでアレックス を確認してください)は、配列が与えられ、パラメータ1が文字列であることを期待(閲覧:C:\ユーザー\ Bof3ss37 \ Desktop \ socia lwall_v1.0.3 \ resources \ views \ frontend \ user \ busquedaBoxeadores.blade.php) –

+0

@CesarGarciaそれでは、どの$投稿をすべきかを決める必要がありますか?配列の場合は配列として定義し、foreach文で表示します。答えの例を –

+0

ありがとうございました! 実行中です! Oohhhはこの笑に時間を費やしても、まあ前に尋ねる必要があります.. –

0

が、それはbusquedaGetで定義されていないとbusquedaPostで、それはコレクションです:

<p> Hello, {{ $posts }} </p> 

で:交換してください。

こんにちは、{{$ポスト}}

まずあなたがbusquedaGetでのデフォルト値を定義し、それがコンテンツだ表示するコレクションをループにしてみてくださいする必要があります。

関連する問題