I have a problem to use ajax on Laravel to each data on relationship one to many. I'm trying to use ajax but return undefined.
This is Code if using Laravel foreach
<div id="project-data">
@foreach ($projectstatus as $project)
<li>{{$project->status}}</li>
@foreach($projectstatus->project as $projectlist)
<li>{{$projectlist->project_name}}</li>
@endforeach
@endforeach
</div>
I'm trying using jquery for each This is My Code
function getDataProyek(){
$.ajax({
url: "{{ url('dt.proyek') }}",
type: "GET",
dataType: "JSON",
success : function(data) {
jQuery.each(data, function(index,project) {
$('#proyek-data').append('<li>'+project.status+'</li>'+
<li>'+project.project.project_name+'</li>');
});
}
});
}
This is My Controller
public function dtproyek()
{
$projectstatus= Status::with('project')->orderBy('created_at','ASC')->get();
return $projectstatus;
}
This is json return
[
{
id: "1",
status: "Waiting",
created_at: "2018-07-30 12:24:25",
updated_at: "2018-07-30 12:24:25",
project: [
{
id: "2",
project_name: "Project 1",
created_at: "2018-08-11 11:59:51",
updated_at: "2018-09-24 07:49:38",
}
]
}
]