2016-03-28 20 views
2

Birden fazla giriş arama sorgusu yapıyorum ve yardıma ihtiyacım var çünkü tam olarak bunu yapmamayı bilmiyorum çünkü tüm belgeleri okudum ve anlayamadım.Şimdi kontrolör .....Laravel Çoklu Girişler Arama 4.2

Ayrıca ben gerçekten ben show.blade in istediğiniz bilgileri aramak için nasıl takdir ediyorum! Herhangi bir yardım için teşekkür ederiz!

Endeksi bıçak

<div class="panel-body"> 
     <div class="form-group"> 
      <div><h4></h4></div> 
      <div class="form-group col-md-4"> 
       {{ Form::open(array('action' => array('[email protected]'), 'class'=>'form width88', 'role'=>'search', 'method' => 'GET')) }} 
       <div id="prefetch"> 
        {{ Form::text('name', null, array('class' => 'typeahead form-group form-control', 'placeholder' => 'name...')) }} 
        {{ Form::text('lastname', null, array('class' => 'form-group form-control', 'placeholder' => 'lastname...')) }} 
        {{--  {{ Form::text('id', null, array('class' => 'form-group form-control', 'placeholder' => 'id...')) }} 
         {{ Form::text('user-seminars', null, array('class' => 'form-group form-control', 'placeholder' => 'Class tha is enrolled...')) }} 
         {{ Form::text('user-class', null, array('class' => 'form-group form-control', 'placeholder' => 'Class that belongs...')) }} 
         {{ Form::text('user-annex', null, array('class' => 'form-group form-control', 'placeholder' => 'Department that belongs...')) }} 
         {{ Form::text('type', null, array('class' => 'form-group form-control', 'placeholder' => 'User type...')) }} 
         {{ Form::text('date_created', null, array('class' => 'form-group form-control', 'placeholder' => 'date created account...')) }} 
         {{ Form::text('date_enrolled', null, array('class' => 'form-group form-control', 'placeholder' => 'date enrolled in class...')) }} 

yolları

Route::get('users/index', '[email protected]'); 
     Route::get('users/search', '[email protected]'); 
     Route::get('users/show', '[email protected]'); 

UserContoller

public function index(){ 

    return View::make('user.index'); 
} 

public function search(){ 

    return View::make('user.show'); 

    } 

public function show(){ 

    return View::make('user.show'); 

} 

KULLANICILARI TABLO

id, ad, last_name, vs vs vs Neden dönüş View'dan

cevap

1
public function search(Request $request){ 
    $users = App\User::where('firstname',$request->name) 
      ->orWhere('lastname',$request->lastname) 
      ->orWhere('id',$request->id) 
      // more orWhere Clause 
      ->get(); 

    return View::make('user.show',compact('users')); 

} 

public function show($id){ 
    $user = App\User::find($id); 

    return View::make('user.show',compact('user')); 
} 

:: ('user.show') iki farklı kaynaklar işlemek için yapmak?

+0

ben bu çalışacağı ve u adam evet ben :: iki defa dönüş görünümü gerek o^_^deneme oldu dont yapmak ve bunu unuttum sana geri –

+0

Thax olsun! –

0

i onun form işlemi

kodunuzu gördüğü ilk şey

{{ Form::open(array('action' => array('[email protected]'), 'class'=>'form width88', 'role'=>'search', 'method' => 'GET')) }} 

{{ Form::open(array('action' => array('users/search'), 'class'=>'form width88', 'role'=>'search', 'method' => 'GET')) }} 

kontrolör eğlenceli kısmıdır olmalıdır. Eğer gerekli tüm girdilerin arıyorsanız eğer doğrulamak gerekir ilk

//first we set the inputs rultes 
$data = Input::all(); 
$rules = array(
     'name'  => 'required', 
     'lastname' => 'required', 
     //rest of the inputs that are required 

); 
//then we use the validator method 
$val = Validator::make($data,$rules); 
if($val->fails()) 
{ 
     /*redirect to the form again, you can set errors with session 
     or ->withError($validator)*/ 
     return Redirect::back(); 
} 
then you make your query 
$user = User::where('name','=',$data['name']) 
     ->where('lastname','=',$data['lastname']) 
     //more where('field','=','value') 
     ->get(); 

alanlar sadece

$user = User::where('name','=',$data['name']) 
     ->orWhere('lastname','=',$data['lastname']) 
     //more orWhere('field','=','value') 
     ->get(); 

ile sorgu yapmak ve nihayet için sonuç döndürmez gerekli öyle ise görünüm gibi:

return View::make('user.show')->with('user',$user); 
+0

İlginiz için teşekkür ederim, ama cevabınızdan ihtiyacım olan bilgiyi aldığım her şeyi yapmam gerektiğini düşünüyorum ve sonuçları görmek için deneyeceğim! –

+0

thx için bir cevap çok @CarlosSalazar –