add nova
This commit is contained in:
89
nova/src/Element.php
Normal file
89
nova/src/Element.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @method static static make(string|null $component = null)
|
||||
*/
|
||||
abstract class Element implements JsonSerializable
|
||||
{
|
||||
use AuthorizedToSee;
|
||||
use Makeable;
|
||||
use Metable;
|
||||
use ProxiesCanSeeToGate;
|
||||
|
||||
/**
|
||||
* The element's component.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $component;
|
||||
|
||||
/**
|
||||
* Indicates if the element is only shown on the detail screen.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $onlyOnDetail = false;
|
||||
|
||||
/**
|
||||
* Create a new element.
|
||||
*
|
||||
* @param string|null $component
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($component = null)
|
||||
{
|
||||
$this->component = $component ?? $this->component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the element should be displayed for the given request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(Request $request)
|
||||
{
|
||||
return $this->authorizedToSee($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component name for the element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function component()
|
||||
{
|
||||
return $this->component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify that the element should only be shown on the detail view.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function onlyOnDetail()
|
||||
{
|
||||
$this->onlyOnDetail = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the element for JSON serialization.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return array_merge([
|
||||
'component' => $this->component(),
|
||||
'prefixComponent' => false,
|
||||
'onlyOnDetail' => $this->onlyOnDetail,
|
||||
], $this->meta());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user