1

Route:

Route::post('dategraph','Chatbot\TrackerController@dategraph');

Controller:

public function dategraph(Request $request)
{
    $dategraph = DiraStatistics::all()->whereBetween('date_access', [$from, $to])->get();

    $dates = $dategraph('date_access');

    return view('AltHr.Chatbot.graph', compact('dates'));
}

View:

<form id="form-project" role="form" action="{{action('AltHr\Chatbot\TrackerController@dategraph')}}" autocomplete="off" method="POST">

          {{csrf_field()}}
          <!-- <canvas id="myChart" width="150" height="50"></canvas> -->

            <div class="form-group-attached">
              <div class="row">
                  <div class="col-lg-6">
                      <div class="form-group form-group-default required" >
                          <label>From</label>
                          <input type="date" class="form-control" name="from" required>
                      </div>
                  </div>
                  <div class="col-lg-6">
                      <div class="form-group form-group-default required" >
                          <label>To</label>
                          <input type="date" class="form-control" name="to">
                      </div>
                  </div>
              </div>
            </div>
            <button class="btn alt-btn-black btn-xs alt-btn pull-right" type="submit">Next</button>
</form>

Hi guys, so im trying to view the data from the selected dates as the code ive written. But im getting an error. Did i write it correctly? or am i missing something?

10
  • [$from, $to] can't see the values of these in the code. Commented Oct 17, 2017 at 5:39
  • @DanyalSandeelo sorry what do you mean? Commented Oct 17, 2017 at 5:46
  • values of $from and $to, you need to get them from $request as $request->input()['from'] Commented Oct 17, 2017 at 5:49
  • also you are using both all() and get()? Commented Oct 17, 2017 at 5:54
  • what error are you getting? Commented Oct 17, 2017 at 5:59

1 Answer 1

1

You do not have a $from variable. You need to pull out posted variables from the request.

The method get() will return a Collection of objects. You can, for example, turn it to a flat array by plucking the column and turning it toArray()

$dategraph = DiraStatistics::whereBetween(
    'date_access', 
    [
        $request->get('from'),
        $request->get('to')
    ]
)->get();
$dates = $dategraph->pluck('date_access')->toArray();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.