Skip to content

Commit

Permalink
Merge pull request #2 from creode-modules/feature/overwrite_views
Browse files Browse the repository at this point in the history
Adds functionality to render page builder.
  • Loading branch information
creode-dev committed Jan 25, 2024
2 parents dd30fdd + 1aa8166 commit 4a1dc29
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 9 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ You can install the package via composer:
composer require creode/laravel-nova-careers
```

### Setup Page Builder Model
The default Career model has to be replaced to utilise some of the new page builder features, so ensure that you use the new model by editing the existing careers config:

```php
// config/careers.php
return [
...
'model' => Creode\LaravelNovaCareers\Models\NovaCareer::class,
...
];
```

### Publishing Config

You can publish the config file with:

```bash
Expand Down Expand Up @@ -46,18 +60,26 @@ return [

/*
|--------------------------------------------------------------------------
| Careers Email
| Application Email
|--------------------------------------------------------------------------
|
| This value is the email address that careers applications will be sent
| to.
|
*/
'email' => env('CAREERS_EMAIL', ''),
'application_email' => env('CAREERS_EMAIL', ''),

];
```

### Publishing Views

You can publish the views this module utilises with:

```bash
php artisan vendor:publish --tag="nova-careers-views"
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"require": {
"php": "^8.1",
"creode/laravel-careers": "^1.0",
"creode/laravel-careers": "^1.1",
"creode/nova-page-builder": "^1.0",
"illuminate/contracts": "^10.0",
"laravel/nova": "^4.0",
Expand Down
8 changes: 3 additions & 5 deletions config/nova-careers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

/*
|--------------------------------------------------------------------------
| Careers Email
| Application Email
|--------------------------------------------------------------------------
|
| This value is the email address that careers applications will be sent
| to.
|
*/
'email' => env('CAREERS_EMAIL', ''),
'application_email' => env('CAREERS_EMAIL', ''),

/*
|--------------------------------------------------------------------------
Expand All @@ -41,7 +41,5 @@
| List of block names to be excluded from the page builder.
|
*/
'excluded_blocks' => [
'imageWithText',
]
'excluded_blocks' => [],
];
11 changes: 11 additions & 0 deletions resources/views/career.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>{{ $career->title }}</h1>
<p>{{ $career->location }}</p>
<p>{{ $career->salary }}</p>
<p>{{ $career->type }}</p>
@if ($career->duration)
<p>{{ $career->duration }}</p>
@endif

@include('page-builder::components', ['components' => $career->components])

@include('nova-careers::partials.apply-button', ['application_url' => $career->application_url])
5 changes: 5 additions & 0 deletions resources/views/partials/apply-button.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@php
$apply_url = $application_url ? $application_url : config('nova-careers.application_email');
@endphp

<a href="mailto:{{ $apply_url }}">Apply</a>
10 changes: 10 additions & 0 deletions src/Http/Controllers/NovaCareerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Creode\LaravelNovaCareers\Http\Controllers;

use Creode\LaravelCareers\Http\Controllers\CareerController;

class NovaCareerController extends CareerController
{
protected $view = 'nova-careers::career';
}
8 changes: 7 additions & 1 deletion src/LaravelNovaCareersServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Spatie\LaravelPackageTools\Package;
use Creode\LaravelNovaCareers\Nova\CareerResource;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Creode\LaravelCareers\Http\Controllers\CareerController;
use Creode\LaravelNovaCareers\Http\Controllers\NovaCareerController;

class LaravelNovaCareersServiceProvider extends PackageServiceProvider
{
Expand All @@ -18,7 +20,8 @@ public function configurePackage(Package $package): void
*/
$package
->name('laravel-nova-careers')
->hasConfigFile();
->hasConfigFile()
->hasViews('nova-careers');
}

public function boot()
Expand All @@ -28,6 +31,9 @@ public function boot()
// Load in configuration by default.
$this->mergeConfigFrom(__DIR__.'/../config/nova-careers.php', 'nova-careers');

// Replace default controller so we can override the view that gets rendered.
$this->app->bind(CareerController::class, NovaCareerController::class);

// Register the Model for the CareerResource and the CareerResource itself.
CareerResource::$model = config('careers.model');
Nova::resources([
Expand Down
30 changes: 30 additions & 0 deletions src/Models/NovaCareer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Creode\LaravelNovaCareers\Models;

use Creode\LaravelCareers\Models\Career;
use Creode\NovaPageBuilder\Services\BlockRenderer;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Whitecube\NovaFlexibleContent\Value\FlexibleCast;

class NovaCareer extends Career
{
protected $casts = [
'description' => FlexibleCast::class,
];

/**
* Exposes a set of components from the Page Builder.
*
* @return Attribute
*/
protected function components(): Attribute
{
$blockRendererService = app()->make(BlockRenderer::class);
return Attribute::make(
get: function () use ($blockRendererService) {
return $blockRendererService->render($this->description);
}
);
}
}

0 comments on commit 4a1dc29

Please sign in to comment.