-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
255 additions
and
71 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Http\Controllers; | ||
|
||
class OptionController extends Controller | ||
{ | ||
/** | ||
* Create a new controller instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
public function index() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Interfaces\Options; | ||
|
||
use Cone\Root\Options\Group; | ||
|
||
interface Registry | ||
{ | ||
/** | ||
* Get or create a new group. | ||
*/ | ||
public function group(string $name): Group; | ||
|
||
/** | ||
* Get the option groups. | ||
*/ | ||
public function groups(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Options; | ||
|
||
use Cone\Root\Exceptions\SaveFormDataException; | ||
use Cone\Root\Traits\AsForm; | ||
use Cone\Root\Traits\Authorizable; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
use Throwable; | ||
|
||
class Group | ||
{ | ||
use AsForm; | ||
use Authorizable; | ||
|
||
/** | ||
* Get the key. | ||
*/ | ||
public function getKey(): string | ||
{ | ||
return Str::of($this->getModel())->classBasename()->plural()->kebab()->value(); | ||
} | ||
|
||
/** | ||
* Get the URI key. | ||
*/ | ||
public function getUriKey(): string | ||
{ | ||
return $this->getKey(); | ||
} | ||
|
||
/** | ||
* Get the name. | ||
*/ | ||
public function getName(): string | ||
{ | ||
return __(Str::of($this->getModel())->classBasename()->headline()->plural()->value()); | ||
} | ||
|
||
/** | ||
* Make a new Eloquent query instance. | ||
*/ | ||
public function query(): Builder | ||
{ | ||
return $this->getModelInstance()->newQuery()->with($this->with)->withCount($this->withCount); | ||
} | ||
|
||
/** | ||
* Handle the request. | ||
*/ | ||
public function handleFormRequest(Request $request): void | ||
{ | ||
$this->validateFormRequest($request); | ||
|
||
try { | ||
DB::beginTransaction(); | ||
|
||
$this->resolveFields($request) | ||
->authorized($request) | ||
->visible($request->isMethod('POST') ? 'create' : 'update') | ||
->persist($request, $model); | ||
|
||
DB::commit(); | ||
} catch (Throwable $exception) { | ||
report($exception); | ||
|
||
DB::rollBack(); | ||
|
||
throw new SaveFormDataException($exception->getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Options; | ||
|
||
use Cone\Root\Interfaces\Options\Registry as Contract; | ||
use Cone\Root\Interfaces\Options\Repository; | ||
use Illuminate\Support\Str; | ||
|
||
class Registry implements Contract | ||
{ | ||
/** | ||
* The repository instance. | ||
*/ | ||
public readonly Repository $repository; | ||
|
||
/** | ||
* The option groups. | ||
*/ | ||
protected array $groups = []; | ||
|
||
/** | ||
* Create a new registry instance. | ||
*/ | ||
public function __construct(Repository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
/** | ||
* Get or create a new group. | ||
*/ | ||
public function group(string $key): Group | ||
{ | ||
$this->groups[$key] ??= new Group(Str::headline($key), $key); | ||
|
||
return $this->groups[$key]; | ||
} | ||
|
||
/** | ||
* Get the option groups. | ||
*/ | ||
public function groups(): array | ||
{ | ||
return $this->groups; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters