I'm building a small application on Laravel 5.4
I'm trying to receive dates from a datepicker widget from front end and parsing it into Carbon date format something like this:
Carbon\Carbon::parse($request->schedule)->toDateTimeString();
In continuation with my previous questions: How to format date receiving through Vuejs Datepicker in laravel , I successfully added this to my database, and while calling it I'm placing an accessor in my model and trying to fetch the date in diffForHumans()
format which was my previous question: A two digit month could not be found Data missing in Laravel , this works perfectly fine whenever I'm fetching the model, until I'm not assigning this schedule attribute to any other variable, Now while retrieving the models in the controller and assigning to the a value with something like this:
public function getData()
{
$user = Auth::user();
$summaries = InteractionSummary::all();
$meetings = [];
foreach($summaries as $summary)
{
$company = [];
$tempData = $summary->interaction->where('user_id', $user->id)->get()->first();
if($tempData)
{
$meeting = Interaction::find($tempData->id);
$tempData->schedule = $meeting->schedule;
$meetings[] = $tempData;
}
}
return response()->json(['meetings' => $meetings], 200);
}
I'm getting the same error:
A two digit month could not be found Data missing
And the same works perfectly fine if I do:
public function getFutureData()
{
$user = Auth::user();
$currentTime = Carbon::now();
$interactions = $user->interaction->where('schedule', '>=', $currentTime);
$meetings = [];
foreach($interactions as $interaction)
{
$interaction->meeting = $meeting;
$meetings[] = $interaction;
}
return response()->json(['interactions' => $meetings], 200);
}
In my model with the name: Interaction
I'm defining my attribute something like this:
public function getScheduleAttribute($value)
{
return Carbon::parse($value)->diffForHumans();
}
EDIT
FYI: I'm having my InteractionSummary
model and have following relationship:
public function interaction()
{
return $this->belongsTo('App\Interaction');
}
get()
and thenfirst()
in first part of your code ? and can you describe your error in more detail. – BoomaInteractionSummary
model as:public function interaction() { return $this->belongsTo('App\Interaction'); }
– Slumlordschedule
column, that might be a reason for your error. – Booma