将数据重定向回到表格完成的位置Laravel
我有一个表格,控制器从DB中获取数据所请求的数据。然后,我想将其重定向到与表单同一页面,但使用我从数据库中获得的数据。我使用的是Laravel 5.5
这是我的控制器的控制器:页面
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');
}
的控制器:
public function lists() {
$users = User::all();
return view( 'backend.list', compact('users'));
}
在视图中,我尝试了这种方式:
@if(session()->has('timecards'))
@foreach($timecards as $timecard)
<div>{{$timecard->checkin}}</div>
@endforeach
@endif
谢谢
更新:现在我获取了数据,但它以JSON的形式,例如格式,任何关于我如何的想法可以操纵它吗? 我的观点:
@if(session()->has('data'))
{{session('data')}}
@endif
谢谢
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
Update: now i get the data but it is in a json like format, any idea of how i can manipulate it?
my view:
@if(session()->has('data'))
{{session('data')}}
@endif
Thankss
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
在listsstore()中
,在您的路线中,您可以阅读
In listsStore()
and in your route you can read it with