Laravel-datatables: Get SearchBar input val on Server Side !

Created on 23 Dec 2016  ·  3Comments  ·  Source: yajra/laravel-datatables

Get SearchBar input val on Server Side !

Good Morning; I have a problem, is it possible to access the "Value" of serachBar input on the server side? Basically the problem is that I need to filter the query before "return Datatables";

I have SomeThing Like this

  $casa = Casa::where('client_id', Auth::user()->id)->first();

    $guifftCards = guiftcarwin::where('casa', $casa->id)->orderBy('created_at','DESC')->select(['created_at','client_id' ,'id']);


    return Datatables::of($guifftCards)
        ->editColumn('client_id',function ($guifftCard){
            return  HellperFunction::getUserName($guifftCard->client_id);
        }  )
        ->editColumn('id',function ($guifftCard){
            return  HellperFunction::makeValue($guifftCard->id);
        }  )
        ->make();

And i need ...

  $casa = Casa::where('client_id', Auth::user()->id)->first();

  $usersID = Users::where('name', 'LIKE', "%{$SEARCHBAR}%")->pluck('client_id');

    $guifftCards = guiftcarwin::where('casa', $casa->id)->wherein('client_id',$usersID)->orderBy('created_at','DESC')->select(['created_at','client_id' ,'id']);


    return Datatables::of($guifftCards)
        ->editColumn('client_id',function ($guifftCard){
            return  HellperFunction::getUserName($guifftCard->client_id);
        }  )
        ->editColumn('id',function ($guifftCard){
            return  HellperFunction::makeValue($guifftCard->id);
        }  )
        ->make();

Thanks !

  • Operating System: Osx 10.11.1
  • PHP Version : 5.6
  • Laravel Version 5.3
  • Laravel-Datatables Xamp/mysql
question

Most helpful comment

Hi,

Maybe this can answer your question? https://datatables.yajrabox.com/fluent/custom-filter

All 3 comments

Hi,

Maybe this can answer your question? https://datatables.yajrabox.com/fluent/custom-filter

You can access it using request('search.value'). A more advance search can also be done using the link provided by @AdrienPoupa. Thanks!

Thanks AdrienPoupa, it do the job !!

Was this page helpful?
0 / 5 - 0 ratings