Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardh committed Apr 8, 2021
2 parents c2d33bd + b075a96 commit f52429c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
18 changes: 2 additions & 16 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

use \Bernhardh\NovaDynamicViews\Http\Controllers\NovaDynamicViewsController;
/*
|--------------------------------------------------------------------------
| Tool API Routes
Expand All @@ -14,18 +14,4 @@
|
*/

Route::get('{resource}/{method}', function (\Laravel\Nova\Http\Requests\ResourceDetailRequest $request, $resource, $method) {
$resourceClass = $request->resource();
$model = $request->model();
$method = \Illuminate\Support\Str::camel('custom-' . $method . '-components');
$resource = new $resourceClass($model);

if(method_exists($resource, $method)) {
$data = $resource->$method();
if($data) {
return $data;
}
}

return [];
});
Route::get('{resource}/{method}', [NovaDynamicViewsController::class, 'resourceRequestDetails']);
35 changes: 35 additions & 0 deletions src/Http/Controllers/NovaDynamicViewsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Bernhardh\NovaDynamicViews\Http\Controllers;

use Illuminate\Routing\Controller;
use \Laravel\Nova\Http\Requests\ResourceDetailRequest;
use \Illuminate\Support\Str;
/**
* Class NovaDynamicViewsController
* @package Bernhardh\NovaDynamicViews\Http\Controllers
*/
class NovaDynamicViewsController extends Controller
{
/**
* @param ResourceDetailRequest $request
* @param $resource
* @param $method
* @return array
*/
public function resourceRequestDetails(ResourceDetailRequest $request, $resource, $method) {
$resourceClass = $request->resource();
$model = $request->model();
$method = Str::camel('custom-' . $method . '-components');
$resource = new $resourceClass($model);

if(method_exists($resource, $method)) {
$data = $resource->$method();
if($data) {
return $data;
}
}

return [];
}
}

0 comments on commit f52429c

Please sign in to comment.