php - Laravel 3 search function controller -


i still new in laravel. i'm trying create search box searching users username.

what best way create controller laravel search box?

the view have follows:

{{ form::search_open('/users/search') }}     {{ form::search_box('search','admin', array('class' => 'input-medium')) }}     {{ form::submit('search'); }} {{ form::close() }} 

i have controller below:

class users_controller extends base_controller {     public function action_search() {         $userdetail = input::get("username");         $details = user::where('username', '=', input::get('username')) - > first();         return redirect::to_route("users");     } } 

you may try :

route :

route::get('/search', array('as' => 'user.search', 'uses' => 'user@search')); 

view : (search/index.blade.php)

{{ form::open(url::to_route('user.search')) }} {{ $errors->has('username') ? $errors->first('username','<span class="error">:message</span>') : '' }} {{ form::text('username', input::old('username', $username), array('class' => 'input-medium')) }} {{ form::submit('search'); }} {{ form::close() }}  @if ( isset($user) )     @foreach ($user->results $user)         {{ $user->first_name }}         {{ $user->last_name }}     @endforeach @endif 

controller : (controllers/user.php)

class user_controller extends base_controller {     public function action_search()     {         $data['username'] = input::get('username');         if(input::get())         {             $rules=array( 'username' => 'required' );             $validation = validator::make(input::all(), $rules);             if($validation->fails())             {                 return redirect::back()->with_errors($validation)->with_input();             }             else {                 data['user'] = user::where('username', '=', input::get('username'));             }         }         return view::make('search.index', $data);     } } 

model : (models/user.php)

class user extends eloquent {     // ... } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -