@extends('company.layout')
@section('page_title', '募集要項')
@section('content')
@section('structured_data')
@if (isset($recruitment) && is_array($recruitment->table))
@php
function getContent($table, $title) {
foreach ($table as $item) {
if (($item['title'] ?? null) === $title) {
return $item['content'] ?? null;
}
}
return null;
}
function parseSalary($text) {
if (!$text) return null;
if (preg_match('/(\d[\d,]*)/', $text, $matches)) {
$rawValue = floatval(str_replace(',', '', $matches[1]));
// 「万円」表記なら×10,000
$isMan = \Illuminate\Support\Str::contains($text, '万');
$value = $isMan ? $rawValue * 10000 : $rawValue;
// 単位の判定(年・月・時)
$unit = 'HOUR';
if (\Illuminate\Support\Str::contains($text, '月')) {
$unit = 'MONTH';
} elseif (\Illuminate\Support\Str::contains($text, '年')) {
$unit = 'YEAR';
}
return [
"@type" => "MonetaryAmount",
"currency" => "JPY",
"value" => [
"@type" => "QuantitativeValue",
"value" => $value,
"unitText" => $unit
]
];
}
return null;
}
function getEmploymentType($text) {
$map = [
'正社員' => 'FULL_TIME',
'パート' => 'PART_TIME',
'アルバイト' => 'PART_TIME',
'契約社員' => 'CONTRACTOR',
'業務委託' => 'TEMPORARY',
'派遣社員' => 'TEMPORARY',
'期間限定の契約' => 'TEMPORARY',
'インターン' => 'INTERN',
'ボランティア' => 'VOLUNTEER',
'日雇い' => 'PER_DIEM',
'日給制' => 'PER_DIEM',
'その他' => 'OTHER',
];
$matches = [];
foreach ($map as $keyword => $type) {
if (Str::contains($text, $keyword)) {
$matches[] = $type;
}
}
return count($matches) ? array_values(array_unique($matches)) : ['OTHER'];
}
$table = $recruitment->table;
$company = $recruitment->company;
// ヘルパー関数:空でない値のみを返す
function addIfNotEmpty($value) {
return (!empty($value) && trim($value) !== '') ? $value : null;
}
// 構造化データを段階的に構築
$structuredData = [];
$structuredData["@context"] = "https://schema.org";
$structuredData["@type"] = "JobPosting";
$structuredData["title"] = $recruitment->title;
// 各フィールドを条件付きで追加
if ($description = addIfNotEmpty(getContent($table, '仕事内容'))) {
$structuredData["description"] = $description;
}
// identifier(必須)
$structuredData["identifier"] = [
"@type" => "PropertyValue",
"name" => $company->name ?? null,
"value" => $recruitment->id,
];
// 日付
if ($recruitment->created_at) {
$structuredData["datePosted"] = $recruitment->created_at->format('Y-m-d');
}
// 雇用形態
$employmentTypeContent = addIfNotEmpty(getContent($table, '雇用形態'));
if ($employmentTypeContent) {
$employmentType = getEmploymentType($employmentTypeContent);
if (!empty($employmentType) && $employmentType !== ['OTHER']) {
$structuredData["employmentType"] = $employmentType;
}
}
// 採用企業
$hiringOrg = ["@type" => "Organization"];
if ($companyName = addIfNotEmpty($company->name)) {
$hiringOrg["name"] = $companyName;
}
if ($companySameAs = addIfNotEmpty($company->company_url)) {
$hiringOrg["sameAs"] = $companySameAs;
}
if ($companyLogo = addIfNotEmpty($company->logo)) {
$hiringOrg["logo"] = asset('storage/' . $companyLogo);
}
$structuredData["hiringOrganization"] = $hiringOrg;
// 住所(新しい住所フィールドがない場合は表組の勤務地を使用)
$address = ["@type" => "PostalAddress", "addressCountry" => "JP"];
// 新しい住所フィールドをチェック
$hasNewAddressData = false;
if ($postalCode = addIfNotEmpty($recruitment->postal_code)) {
$address["postalCode"] = $postalCode;
$hasNewAddressData = true;
}
if ($prefecture = addIfNotEmpty($recruitment->prefecture)) {
$address["addressRegion"] = $prefecture;
$hasNewAddressData = true;
}
if ($city = addIfNotEmpty($recruitment->city)) {
$address["addressLocality"] = $city;
$hasNewAddressData = true;
}
if ($streetAddress = addIfNotEmpty($recruitment->street_address)) {
$address["streetAddress"] = $streetAddress;
$hasNewAddressData = true;
}
// 新しい住所データがない場合は表組の勤務地を使用
if (!$hasNewAddressData) {
if ($workLocation = addIfNotEmpty(getContent($table, '勤務地'))) {
$address["addressLocality"] = $workLocation;
}
}
$structuredData["jobLocation"] = [
"@type" => "Place",
"address" => $address,
];
// オプション項目
$salary = parseSalary(addIfNotEmpty(getContent($table, '給与(月収または年収)')));
if ($salary) {
$structuredData["baseSalary"] = $salary;
}
if ($workHours = addIfNotEmpty(getContent($table, '勤務時間'))) {
$structuredData["workHours"] = $workHours;
}
if ($educationReq = addIfNotEmpty(getContent($table, '応募資格・条件(学歴等)'))) {
$structuredData["educationRequirements"] = $educationReq;
}
if ($experienceReq = addIfNotEmpty(getContent($table, '応募資格・条件(経験、実績等)'))) {
$structuredData["experienceRequirements"] = $experienceReq;
}
if ($qualifications = addIfNotEmpty(getContent($table, '応募資格・条件(保有資格等)'))) {
$structuredData["qualifications"] = $qualifications;
}
if ($incentive = addIfNotEmpty(getContent($table, 'インセンティブ/賞与'))) {
$structuredData["incentiveCompensation"] = $incentive;
}
if ($benefits = addIfNotEmpty(getContent($table, '福利厚生'))) {
$structuredData["jobBenefits"] = $benefits;
}
// 最終的にnullを完全除去
function removeNullValues($array) {
foreach ($array as $key => $value) {
if (is_array($value)) {
$array[$key] = removeNullValues($value);
} elseif ($value === null) {
unset($array[$key]);
}
}
return $array;
}
$structuredData = removeNullValues($structuredData);
@endphp
@endif
@endsection
{{ $recruitment->title }}
@if ($recruitment->table)
@foreach ($recruitment->table as $row)
| {{ $row['title'] }} |
{!! nl2br($row['content']) !!} |
@endforeach
@endif
@if ($recruitment->form_note)
| 企業からのコメント |
{!! nl2br($recruitment->form_note) !!} |
@endif
応募フォーム
@include('company.part.entry')
@endsection