Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/whitecube/nova-page
Browse files Browse the repository at this point in the history
  • Loading branch information
voidgraphics committed Apr 15, 2021
2 parents df8d062 + 7c702d2 commit 302265d
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class AboutController extends Controller
}
```

In most cases, this will probably not be very convenient since we alreay registered the current route's template in our routes definitions. Therefore, it is also possible to load the page's content with an `Illuminate\Routing\Route` instance using the `loadFromRoute($route, $locale = null, $current = true)` method:
In most cases, this will probably not be very convenient since we alreay registered the current route's template in our routes definitions. Therefore, it is also possible to load the page's content with an `Illuminate\Routing\Route` instance using the `loadForRoute($route, $locale = null, $current = true)` method:

```php
use Illuminate\Http\Request;
Expand All @@ -225,14 +225,14 @@ class AboutController extends Controller

public function show(Request $request, Manager $page)
{
$page->loadFromRoute($request->route());
$page->loadForRoute($request->route());
return view('pages.about');
}

}
```

Anyway, if no locale is provided, NovaPage will use the application's current locale (using `App::getLocale()`). By default, loading a page's content will define it as the current page, making its attributes accessible with the `Page` facade. If you just want to load content without setting it as the current page, you should call `load()` or `loadFromRoute()` with `$current` set to `false`.
Anyway, if no locale is provided, NovaPage will use the application's current locale (using `App::getLocale()`). By default, loading a page's content will define it as the current page, making its attributes accessible with the `Page` facade. If you just want to load content without setting it as the current page, you should call `load()` or `loadForRoute()` with `$current` set to `false`.

## Front-end Template Usage

Expand Down
4 changes: 2 additions & 2 deletions resources/views/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}
}" class="cursor-pointer flex items-center font-normal dim text-white mb-6 text-base no-underline">
<svg class="sidebar-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="var(--sidebar-icon)" d="M6 2h9a1 1 0 0 1 .7.3l4 4a1 1 0 0 1 .3.7v13a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4c0-1.1.9-2 2-2zm9 2.41V7h2.59L15 4.41zM18 9h-3a2 2 0 0 1-2-2V4H6v16h12V9zm-2 7a1 1 0 0 1-1 1H9a1 1 0 0 1 0-2h6a1 1 0 0 1 1 1zm0-4a1 1 0 0 1-1 1H9a1 1 0 0 1 0-2h6a1 1 0 0 1 1 1zm-5-4a1 1 0 0 1-1 1H9a1 1 0 1 1 0-2h1a1 1 0 0 1 1 1z"/></svg>
<span class="sidebar-label">{{ config('novapage.labels.pages') }}</span>
<span class="sidebar-label">{{ __(config('novapage.labels.pages')) }}</span>
</router-link>
<router-link tag="h3" :to="{
name: 'index',
Expand All @@ -14,5 +14,5 @@
}
}" class="cursor-pointer flex items-center font-normal dim text-white mb-6 text-base no-underline">
<svg class="sidebar-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="var(--sidebar-icon)" class="heroicon-ui" d="M9 4.58V4c0-1.1.9-2 2-2h2a2 2 0 0 1 2 2v.58a8 8 0 0 1 1.92 1.11l.5-.29a2 2 0 0 1 2.74.73l1 1.74a2 2 0 0 1-.73 2.73l-.5.29a8.06 8.06 0 0 1 0 2.22l.5.3a2 2 0 0 1 .73 2.72l-1 1.74a2 2 0 0 1-2.73.73l-.5-.3A8 8 0 0 1 15 19.43V20a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-.58a8 8 0 0 1-1.92-1.11l-.5.29a2 2 0 0 1-2.74-.73l-1-1.74a2 2 0 0 1 .73-2.73l.5-.29a8.06 8.06 0 0 1 0-2.22l-.5-.3a2 2 0 0 1-.73-2.72l1-1.74a2 2 0 0 1 2.73-.73l.5.3A8 8 0 0 1 9 4.57zM7.88 7.64l-.54.51-1.77-1.02-1 1.74 1.76 1.01-.17.73a6.02 6.02 0 0 0 0 2.78l.17.73-1.76 1.01 1 1.74 1.77-1.02.54.51a6 6 0 0 0 2.4 1.4l.72.2V20h2v-2.04l.71-.2a6 6 0 0 0 2.41-1.4l.54-.51 1.77 1.02 1-1.74-1.76-1.01.17-.73a6.02 6.02 0 0 0 0-2.78l-.17-.73 1.76-1.01-1-1.74-1.77 1.02-.54-.51a6 6 0 0 0-2.4-1.4l-.72-.2V4h-2v2.04l-.71.2a6 6 0 0 0-2.41 1.4zM12 16a4 4 0 1 1 0-8 4 4 0 0 1 0 8zm0-2a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></svg>
<span class="sidebar-label">{{ config('novapage.labels.options') }}</span>
<span class="sidebar-label">{{ __(config('novapage.labels.options')) }}</span>
</router-link>
4 changes: 4 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use Whitecube\NovaPage\Http\Controllers\Page\IndexController as PageResourceIndexController;
use Whitecube\NovaPage\Http\Controllers\Page\CountController as PageResourceCountController;
use Whitecube\NovaPage\Http\Controllers\Page\UpdateController as PageResourceUpdateController;
use Whitecube\NovaPage\Http\Controllers\Page\FieldDestroyController as PageFieldDestroyController;
use Whitecube\NovaPage\Http\Controllers\Option\IndexController as OptionResourceIndexController;
use Whitecube\NovaPage\Http\Controllers\Option\CountController as OptionResourceCountController;
use Whitecube\NovaPage\Http\Controllers\Option\UpdateController as OptionResourceUpdateController;
use Whitecube\NovaPage\Http\Controllers\Option\FieldDestroyController as OptionFieldDestroyController;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -43,7 +45,9 @@
Route::get('/nova-api/nova-page', PageResourceIndexController::class . '@handle');
Route::get('/nova-api/nova-page/count', PageResourceCountController::class . '@show');
Route::put('/nova-api/nova-page/{resourceId}', PageResourceUpdateController::class . '@handle');
Route::delete('/nova-api/nova-page/{resourceId}/field/{field}', PageFieldDestroyController::class . '@handle');

Route::get('/nova-api/nova-option', OptionResourceIndexController::class . '@handle');
Route::get('/nova-api/nova-option/count', OptionResourceCountController::class . '@show');
Route::put('/nova-api/nova-option/{resourceId}', OptionResourceUpdateController::class . '@handle');
Route::delete('/nova-api/nova-option/{resourceId}/field/{field}', OptionFieldDestroyController::class . '@handle');
15 changes: 15 additions & 0 deletions src/Http/Controllers/Option/FieldDestroyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Whitecube\NovaPage\Http\Controllers\Option;

use Whitecube\NovaPage\Http\Controllers\ResourceFieldDestroyController;

class FieldDestroyController extends ResourceFieldDestroyController
{
/**
* The queried resource's name
*
* @var string
*/
protected $resourceName = 'nova-option';
}
15 changes: 15 additions & 0 deletions src/Http/Controllers/Page/FieldDestroyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Whitecube\NovaPage\Http\Controllers\Page;

use Whitecube\NovaPage\Http\Controllers\ResourceFieldDestroyController;

class FieldDestroyController extends ResourceFieldDestroyController
{
/**
* The queried resource's name
*
* @var string
*/
protected $resourceName = 'nova-page';
}
46 changes: 46 additions & 0 deletions src/Http/Controllers/ResourceFieldDestroyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Whitecube\NovaPage\Http\Controllers;

use Illuminate\Routing\Controller;
use Laravel\Nova\DeleteField;
use Laravel\Nova\Fields\File;
use Laravel\Nova\Http\Requests\UpdateResourceRequest;

abstract class ResourceFieldDestroyController extends Controller
{
/**
* The queried resource's name
*
* @var string
*/
protected $resourceName;

/**
* Update a resource.
*
* @param \Laravel\Nova\Http\Requests\UpdateResourceRequest $request
* @return \Illuminate\Http\Response
*/
public function handle(UpdateResourceRequest $request)
{
$route = call_user_func($request->getRouteResolver());
$route->setParameter('resource', $this->resourceName);
$request->findResourceOrFail()->authorizeToUpdate($request);

$resource = $request->newResource();
$field = $resource->updateFields($request)->findFieldByAttribute($request->field);

if (!($field instanceof File)) {
abort(404);
}

$template = $request->findModelQuery()->firstOrFail();

DeleteField::forRequest(
$request,
$field,
$template
)->save();
}
}
1 change: 1 addition & 0 deletions src/Http/Controllers/ResourceIndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function handle(ResourceIndexRequest $request, Manager $manager)
'resources' => $paginator->getCollection()->values()->map->serializeForIndex($request),
'prev_page_url' => $paginator->previousPageUrl(),
'next_page_url' => $paginator->nextPageUrl(),
'per_page' => $paginator->perPage(),
'softDeletes' => null,
]);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/OptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class OptionResource extends StaticResource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'nova-option';

/**
* Get the URI key for the resource.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class PageResource extends StaticResource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'nova-page';

/**
* Get the URI key for the resource.
*
Expand Down
3 changes: 1 addition & 2 deletions src/Pages/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,11 @@ public function setDate($moment, $date = null)
* @param Closure $closure
* @return mixed
*/
public function setDateIf($moment, $date = null, Closure $closure)
public function setDateIf($moment, $date, Closure $closure)
{
if(!($date instanceof Carbon)) {
$date = new Carbon($date);
}

if($closure($date, $this->getDate($moment))) {
return $this->setDate($moment, $date);
}
Expand Down
1 change: 1 addition & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
|--------------------------------------------------------------------------
|
| How should we name the links in Laravel Nova's sidebar?
| Note that translation keys can be used instead of plain text.
|
*/
'labels' => [
Expand Down

0 comments on commit 302265d

Please sign in to comment.