<?php

namespace App\Http\Controllers;

use App\Job;
use Illuminate\Http\Request;

class AppController extends Controller
{
    public function index() {
        return view('app');
    }

    public function show() {
        $jobs = Job::select('jobs.id', 'jobs.job_title', 'jobs.job_type', 'jobs.department', 'jobs.num', 'companies.bts', 'companies.mrt', 'companies.arl', 'companies.imageCompany', 'companies.company_name', 'companies.amphoe', 'companies.province','jobs.created_at')
            ->join('companies', 'jobs.user_id', 'companies.user_id')
            ->orderBy('jobs.created_at', 'desc')
            ->get();
        return response()->json(['jobs' => $jobs]);
    }

    public function detail($id) {
        $job = Job::join('companies', 'jobs.user_id', 'companies.user_id')
                ->where('jobs.id', $id)
                ->first();
        return response()->json(['job' => $job]);
    }
}
