I have a form from which the controller gets the data requested from the db. I want to then redirect to the same page as the form but with the data i got from the db. I am using laravel 5.5
This is my controller for the store:
public function listsStore(Request $request) {
$data = $request->all();
$user = $request->user;
$day = date('Y-m-d', strtotime($request->day));
$from = date('Y-m-d', strtotime($request->from));
$to = date('Y-m-d', strtotime($request->to));
$radio = $data['radio-btn'];
// dd($user, $from, $to);
// dd($radio);
if($radio === 'tasks') {
if($request->day) {
$tasks = Task::where('user_id', $user)
->whereDate('start', $day)
->orderBy('start','DESC')
->get();
// dd($tasks);
return redirect()->back()->with('tasks', $tasks);
}else{ // gets for the range of dates requested
$tasks = Task::where('user_id', $user)
->whereBetween('start',[$from, $to])
->orderBy('start','DESC')
->get()
->groupBy(function($date) {
return Carbon::parse($date->start)->format('Y-m-d');
});
// dd($tasks);
return redirect()->back()->with('tasks', $tasks);
}
}elseif($radio === 'timecards'){ //IF REQUEST IS TIMECARDS
if($request->day) { //gets for the day requested
$timecards = Timecard::where('user_id',$user)
->whereDate('checkin', $day)
->orderBy('checkin','DESC')
->get();
// dd($timecards);
return redirect()->back()->with('timecards', $timecards);
} else{ // gets for the range of dates requested
$timecards = Timecard::where('user_id', $user)
->whereBetween('checkin',[$from, $to])
->orderBy('checkin','DESC')
->get()
->groupBy(function($date) {
return Carbon::parse($date->checkin)->format('Y-m-d');
});
// dd($timecards);
return redirect()->back()->with('timecards', $timecards);
}
}
// return redirect('backend.list');
}
controller for the page:
public function lists() {
$users = User::all();
return view( 'backend.list', compact('users'));
}
and in the view i tried this way:
@if(session()->has('timecards'))
@foreach($timecards as $timecard)
<div>{{$timecard->checkin}}</div>
@endforeach
@endif
Thank you