2016-03-28 13 views
2

Ich mache eine Suche mit mehreren Eingaben und ich brauche Hilfe, weil ich nicht weiß, wie genau ich das tun kann Ich habe die gesamte Dokumentation gelesen und ich habe es nicht verstanden. Jetzt bin ich in der stecken Controller .....Laravel Multiple Inputs Suche 4.2

auch würde ich wirklich schätzen, wie die Informationen nennen, die ich möchte in der show.blade! Danke für jede Hilfe!

Index Klinge

<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...')) }} 

Routen

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'); 

} 

Benutzer-Tabelle

id, Vorname, last_name, etc etc etc

Antwort

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')); 
} 

Warum sind Sie Rückkehr Ansicht mit :: machen ('user.show') zu machen, zwei verschiedene Ressourcen?

+0

ich dies versuchen und –

+0

Thax zu Ihnen zurück u Mann ja ich brauche nicht zwei Mal der Rückansicht :: macht es aus experimentieren^_^war, und ich habe es vergessen! –

0

das erste, was ich ist die Form Aktion zu sehen

Code

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

sollte

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

der Controller ist der spaßige Teil sein. wenn Sie für alle Eingänge der Suche erforderlich sind, sollten Sie es zuerst

//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(); 

validieren, wenn die Felder Arent erforderlich Sie nur die Abfrage mit

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

machen und schließlich kehren Sie Ihr Ergebnis auf die Ansicht wie:

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

danke für die aswering aber ich denke nicht, dass ich alles tun muss, dass ich die Informationen nehme, die ich von Ihrer Antwort brauche, und ich werde es versuchen, um die Ergebnisse zu sehen! –

+0

thx viel für Ihre Antwort @CarlosSalazar –