Skip to content

Laravel quickstart

A Laravel career site for Northwilds with a list of open jobs, job pages and each job's own application form, sent with the PHP SDK.

Tutorial7 min read

In about 15 minutes you build a Laravel career site for Northwilds that reads its jobs from Careers Orbit. Visitors filter the open jobs, open one, and apply with the job's own form, CV included. One controller and three Blade views do the work, with no JavaScript.

Tested with: Laravel 13.40, PHP 8.5, bifrost-orbit/careers-sdk 0.1.0.

Before you start

You need:

  • At least one published job in Careers Orbit.
  • A public key (careers_pk_…) from API keys. See API keys.
  • PHP 8.3 or later and Composer.

1Create the project

Shell
composer create-project laravel/laravel northwilds-careerscd northwilds-careerscomposer require bifrost-orbit/careers-sdk

Add your settings to .env:

.envShell
CAREERS_API_URL=https://api.bifrostorbit.com/careers/v1CAREERS_PUBLIC_KEY=careers_pk_...

And read them in config/services.php, before the closing ];:

PHP
// config/services.php    'careers' => [        'api_url' => env('CAREERS_API_URL', 'https://api.bifrostorbit.com/careers/v1'),        'public_key' => env('CAREERS_PUBLIC_KEY'),    ],

CVs can be up to 10 MB, and PHP accepts uploads of 2 MB by default. Raise upload_max_filesize to 11M and post_max_size to 12M in php.ini, or start the development server with them:

Shell
php -d upload_max_filesize=11M -d post_max_size=12M artisan serve

2Register the client

One client serves the whole app. Replace app/Providers/AppServiceProvider.php:

PHP
<?php// app/Providers/AppServiceProvider.phpnamespace App\Providers;use BifrostOrbit\Careers\Client;use Illuminate\Support\ServiceProvider;class AppServiceProvider extends ServiceProvider{    public function register(): void    {        $this->app->singleton(Client::class, fn () => new Client(            publicKey: config('services.careers.public_key'),            apiUrl: config('services.careers.api_url'),            locale: 'en',        ));    }    public function boot(): void    {        //    }}

3Add the routes

Replace routes/web.php:

PHP
<?php// routes/web.phpuse App\Http\Controllers\CareersController;use Illuminate\Support\Facades\Route;Route::get('/careers', [CareersController::class, 'index'])->name('careers.index');Route::get('/careers/{slug}', [CareersController::class, 'show'])->name('careers.show');Route::post('/careers/{slug}', [CareersController::class, 'apply'])->name('careers.apply');

4Write the controller

PHP
<?php// app/Http/Controllers/CareersController.phpnamespace App\Http\Controllers;use BifrostOrbit\Careers\Client;use BifrostOrbit\Careers\Exception\CareersException;use BifrostOrbit\Careers\Upload;use Illuminate\Http\Request;use Illuminate\Http\UploadedFile;class CareersController extends Controller{    public function __construct(private Client $careers) {}    public function index(Request $request)    {        $query = $request->only(['q', 'department', 'location']);        return view('careers.index', [            'jobs' => $this->careers->getJobs(array_filter($query)),            'filters' => $this->careers->getFilters(),            'query' => $query,        ]);    }    public function show(string $slug)    {        $job = $this->careers->findJob($slug) ?? abort(404);        return view('careers.show', ['job' => $job]);    }    public function apply(Request $request, string $slug)    {        $job = $this->careers->findJob($slug) ?? abort(404);        $request->validate(['privacyAccepted' => 'accepted'], ['privacyAccepted.accepted' => 'Please read and accept the privacy notice.']);        $upload = fn (?UploadedFile $file) => $file?->isValid()            ? Upload::fromPath($file->getRealPath(), $file->getClientOriginalName(), $file->getMimeType())            : null;        $fields = [];        foreach (['phone', 'coverLetter', 'linkedin', 'location', 'salaryExpectation', 'startDate'] as $field) {            if ($job['form']['fields'][$field] !== 'off') {                $fields[$field] = $request->input($field);            }        }        $answers = [];        $questionFiles = [];        foreach ($job['form']['questions'] as $question) {            $name = 'q-'.$question['id'];            if ($question['kind'] === 'file') {                if ($file = $upload($request->file($name))) {                    $questionFiles[$question['id']] = $file;                }            } else {                $answers[$question['id']] = $request->input($name);            }        }        try {            $this->careers->apply($slug, [                'firstName' => $request->input('firstName'),                'lastName' => $request->input('lastName'),                'email' => $request->input('email'),                ...$fields,                'answers' => $answers,                'privacyVersion' => (int) $request->input('privacyVersion'),                'privacyAccepted' => true,                'source' => 'northwilds.com',            ], array_filter([                'cv' => $upload($request->file('cv')),                'questions' => $questionFiles,            ]));        } catch (CareersException $error) {            return back()->withInput()->withErrors(['application' => $error->getMessage()]);        }        return redirect()->route('careers.show', $slug)->with('sent', true);    }}
  • getJobs answers the live jobs, newest first, with total. getFilters answers the departments and locations that have live jobs, with counts.
  • findJob answers null for a job that is closed, scheduled or gone, and the page answers 404.
  • Answers are keyed by question id. The form in step 6 names each question's field q- and the question's id. Choice answers are option ids, yes or no answers are yes or no, and a question with several choices sends a list.
  • Standard fields the job has switched off are left out. privacyVersion is the version of the privacy notice the candidate saw.
  • Upload::fromPath reads the uploaded file, with its name and type, for the SDK to send.
  • A refused application throws a CareersException with a message candidates can read, such as "The privacy notice has just changed. Reload the page and read it again." The controller sends the candidate back to the form with it, and with what they typed.
  • After sending, the controller redirects to the job page, so reloading never sends the application twice.

5List the jobs

Blade
{{-- resources/views/careers/layout.blade.php --}}<!DOCTYPE html><html lang="en"><head>    <meta charset="utf-8">    <meta name="viewport" content="width=device-width">    <title>@yield('title')</title>    @hasSection('description')<meta name="description" content="@yield('description')">@endif    @stack('head')</head><body>    <header><a href="{{ route('careers.index') }}">Northwilds careers</a></header>    <main>@yield('content')</main></body></html>
Blade
{{-- resources/views/careers/index.blade.php --}}@extends('careers.layout')@section('title', 'Jobs at Northwilds')@section('content')    <h1>Jobs at Northwilds</h1>    <form method="get">        <input name="q" type="search" placeholder="Search" value="{{ $query['q'] ?? '' }}">        <select name="department">            <option value="">All departments</option>            @foreach ($filters['departments'] as $option)                <option value="{{ $option['value'] }}" @selected(($query['department'] ?? '') === $option['value'])>{{ $option['label'] }} ({{ $option['count'] }})</option>            @endforeach        </select>        <select name="location">            <option value="">All locations</option>            @foreach ($filters['locations'] as $option)                <option value="{{ $option['value'] }}" @selected(($query['location'] ?? '') === $option['value'])>{{ $option['label'] }} ({{ $option['count'] }})</option>            @endforeach        </select>        <button type="submit">Filter</button>    </form>    <p>{{ $jobs['total'] }} {{ $jobs['total'] === 1 ? 'job' : 'jobs' }}</p>    <ul>        @foreach ($jobs['items'] as $job)            <li>                <a href="{{ route('careers.show', $job['slug']) }}">{{ $job['title'] }}</a>                <p>{{ implode(' · ', array_filter([$job['department']['name'] ?? null, implode(', ', array_column($job['locations'], 'city')), $job['employmentTypeLabel'], $job['remoteLabel']])) }}</p>                @if ($job['salary'])                    <p>{{ $job['salary']['text'] }}</p>                @endif            </li>        @endforeach    </ul>@endsection

Check it: run the development server and open http://localhost:8000/careers. You see your open jobs, such as "Mountain guide, Lofoten" with "Guiding · Reine · Temporary · On site". Pick Guiding and select Filter: only the guiding jobs stay.

6Show a job and its form

Blade
{{-- resources/views/careers/show.blade.php --}}@extends('careers.layout')@section('title', $job['seo']['title'])@section('description', $job['seo']['description'])@push('head')    <script type="application/ld+json">{!! json_encode($job['jobPosting'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) !!}</script>@endpush@php    $fields = $job['form']['fields'];    $standard = [        'phone' => ['Phone', 'tel'],        'linkedin' => ['LinkedIn profile', 'url'],        'location' => ['Where you live', 'text'],        'salaryExpectation' => ['Salary expectation', 'text'],        'startDate' => ['Earliest start date', 'date'],    ];@endphp@section('content')    <p><a href="{{ route('careers.index') }}">All jobs</a></p>    <h1>{{ $job['title'] }}</h1>    <p>{{ implode(' · ', array_filter([$job['department']['name'] ?? null, implode(', ', array_column($job['locations'], 'city')), $job['employmentTypeLabel'], $job['remoteLabel']])) }}</p>    @if ($job['salary'])        <p>{{ $job['salary']['text'] }}</p>    @endif    <div>{!! $job['description'] !!}</div>    @if (session('sent'))        <p role="status">Thank you. We have your application and will be in touch.</p>    @else        <form method="post" action="{{ route('careers.apply', $job['slug']) }}" enctype="multipart/form-data">            @csrf            <h2>Apply for this job</h2>            <input type="hidden" name="privacyVersion" value="{{ $job['privacy']['version'] }}">            @if ($errors->any())                <p role="alert">{{ $errors->first() }}</p>            @endif            <label>First name <input name="firstName" autocomplete="given-name" value="{{ old('firstName') }}" required></label>            <label>Last name <input name="lastName" autocomplete="family-name" value="{{ old('lastName') }}" required></label>            <label>Email <input name="email" type="email" autocomplete="email" value="{{ old('email') }}" required></label>            @foreach ($standard as $name => [$label, $type])                @if ($fields[$name] !== 'off')                    <label>{{ $label }} <input name="{{ $name }}" type="{{ $type }}" value="{{ old($name) }}" @required($fields[$name] === 'required')></label>                @endif            @endforeach            @if ($fields['cv'] !== 'off')                <label>CV (PDF or Word, up to 10 MB) <input name="cv" type="file" accept=".pdf,.doc,.docx" @required($fields['cv'] === 'required')></label>            @endif            @if ($fields['coverLetter'] !== 'off')                <label>Cover letter <textarea name="coverLetter" rows="6" @required($fields['coverLetter'] === 'required')>{{ old('coverLetter') }}</textarea></label>            @endif            @foreach ($job['form']['questions'] as $question)                @php($name = 'q-'.$question['id'])                @switch($question['kind'])                    @case('yesNo')                        <fieldset>                            <legend>{{ $question['label'] }}</legend>                            <label><input type="radio" name="{{ $name }}" value="yes" @checked(old($name) === 'yes') @required($question['required'])> Yes</label>                            <label><input type="radio" name="{{ $name }}" value="no" @checked(old($name) === 'no')> No</label>                        </fieldset>                        @break                    @case('choice')                        <fieldset>                            <legend>{{ $question['label'] }}</legend>                            @foreach ($question['options'] as $option)                                <label><input type="radio" name="{{ $name }}" value="{{ $option['id'] }}" @checked(old($name) === $option['id']) @required($question['required'])> {{ $option['label'] }}</label>                            @endforeach                        </fieldset>                        @break                    @case('multiChoice')                        <fieldset>                            <legend>{{ $question['label'] }}</legend>                            @foreach ($question['options'] as $option)                                <label><input type="checkbox" name="{{ $name }}[]" value="{{ $option['id'] }}" @checked(in_array($option['id'], old($name, []), true))> {{ $option['label'] }}</label>                            @endforeach                        </fieldset>                        @break                    @case('longText')                        <label>{{ $question['label'] }} <textarea name="{{ $name }}" rows="4" @required($question['required'])>{{ old($name) }}</textarea></label>                        @break                    @case('file')                        <label>{{ $question['label'] }} <input name="{{ $name }}" type="file" accept=".pdf,.doc,.docx" @required($question['required'])></label>                        @break                    @default                        <label>{{ $question['label'] }} <input name="{{ $name }}" type="{{ $question['kind'] }}" value="{{ old($name) }}" @required($question['required'])></label>                @endswitch            @endforeach            <p>{{ $job['privacy']['text'] }}</p>            <label><input type="checkbox" name="privacyAccepted" value="1" required> I have read the privacy notice</label>            <button type="submit">Send application</button>        </form>    @endif@endsection
  • The JSON-LD script carries the job's JobPosting data, which Google for Jobs reads. JSON_HEX_TAG keeps a < in the text from closing the script early.
  • description is HTML written in Careers Orbit, cleaned before it is sent, so it is printed with {!! !!}. Everything else is escaped.
  • job.form.fields says for each standard field whether it is required, optional or off, and job.form.questions lists the questions with their kind.
  • The privacy notice must be shown and accepted. Careers Orbit refuses an application without it.

Check it: open a job, fill in the form with a test CV and select Send application. The page says "Thank you". In Careers Orbit, the application is in the job's first stage, with the answers and the CV, and its source is northwilds.com.

Next steps

  • Show jobs in other languages: Pass locale: 'de' to the client, or ['locale' => 'de'] to each call. Text that isn't translated falls back to your main language.
  • Cache the pages: Keep answers in Laravel's cache and clear them from the website webhook with Webhook::verify and Webhook::tags. See The PHP SDK.
  • The delivery API: every field, the talent pool and the candidate portal.
  • Troubleshooting: what each error means.

Was this page helpful?

Read next