Why json encode the timestamp? What is your ideal url?
Apr 4, 2017
3
Level 13
How to encode and decode timstamp?
I'm using created_at as route parameter, but problem is that my url looks like
https://bae.dev/staff/section_student/1/2017-03-22%2000:51:47/attach
so i was thing before passing the url i should encode then returning i should decode so lke, I want like
public function courses_for_students_sections()
{
$courses = Course::where('user_id',Auth::user()->owner->id)->get();
return view('staff.attachment.courses_for_students_sections',compact('courses'));
}
here the viewc "ourses_for_students_sections"
@foreach($courses as $course)
<li><a href="/staff/section_student/{{$course->id}}/{{strtotime($course->created_at)}}/attach">{{ $course->name }}</a></li>
@endforeach
my action controller here for this url
public function section_student_get($course = null, $created_at = null)
{
$students = Student::where('user_id',Auth::user()->owner->id)
->whereHas('courses',function($q) use ($course, $created_at){
$q->where('id',$course)
->where('created_at',$created_at); //here i comparing created_at to strtotime($course->created_at)
})->where('active',1)
->with('courses','courses.sections')
->doesntHave('studentacadmic')
->get();
return view('staff.attachment.section_student',compact('students'));
}
now when click the this link i got errors (as expected because i have not converted this in proper format)
Exception in Carbon.php line 291:
DateTime::__construct(): Failed to parse time string (1490124107) at position 7 (1): Unexpected character
so how can i decode strtotime($course->created_at) to this format "2017-04-02 21:10:25" so that i can compare
thanks
Level 13
i got solution
$date=Carbon::createFromTimeStamp($created_at);
Please or to participate in this conversation.