samedi 22 août 2015

Where sytax in Laravel 5 with paginate feature, search feature

I have a problem when I want to do where user with "userID" for show the data, and integration with search and with paginate. But I got error logic. Maybe someone can help me.

This is my Controller

    public function index()
{
    $q='';
    $from = '';
    $to = '';

    if (Input::get('dateSearchFrom') !='' && Input::get('dateSearchTo') !='') {
        $from = Input::get('dateSearchFrom').' 00:00:00.000';
        $to = Input::get('dateSearchTo').' 23:59:59.999';
    }else if (Input::get('search') !='') {
        $q = Input::get('search');
    }

    if ($q != '') {
        $incomes = Income::latest('created_at')->where('user_id', Auth::user()->id)->orWhere('name','like','%'.$q.'%')->orWhere('money','like','%'.$q.'%')->orWhere('created_at','like','%'.$q.'%')->paginate(4);
    }else if (Input::get('dateSearchFrom') !='' && Input::get('dateSearchTo') !='') {
        $incomes = Income::latest('created_at')->where('user_id', Auth::user()->id)->orWhereBetween('created_at', array($from, $to))->paginate(4);

    }else{
        $incomes = Income::latest('created_at')->where('user_id', Auth::user()->id)->paginate(4);
    }

    $incomes->setPath('income');
    return view('member.income.list')->with([
        'title' => 'Income Data',
        'incomes' => $incomes,
        ]);
}

and this is my model

    use SoftDeletes;

protected $table = 'incomes';

protected $fillable = [
    'id',
    'name',
    'user_id',
    'description',
    'money'
];

So in my website, User can see personal data, and search with data or with date, and my website integration with paginate too.

Thanks you for your time. and sorry about my english.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WL1jA5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire