add nova
This commit is contained in:
33
nova/src/Concerns/HandlesRoutes.php
Normal file
33
nova/src/Concerns/HandlesRoutes.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Concerns;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
trait HandlesRoutes
|
||||
{
|
||||
/**
|
||||
* Get url for Laravel Nova.
|
||||
*
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
public static function url($url)
|
||||
{
|
||||
return rtrim(static::path(), '/').'/'.ltrim((string) $url, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Route Registrar for Nova.
|
||||
*
|
||||
* @param array<int, class-string|string>|null $middleware
|
||||
* @param string|null $prefix
|
||||
* @return \Illuminate\Routing\RouteRegistrar
|
||||
*/
|
||||
public static function router($middleware = null, $prefix = null)
|
||||
{
|
||||
return Route::domain(config('nova.domain', null))
|
||||
->prefix(static::url($prefix))
|
||||
->middleware($middleware ?? config('nova.middleware', []));
|
||||
}
|
||||
}
|
||||
41
nova/src/Concerns/InteractsWithActionEvent.php
Normal file
41
nova/src/Concerns/InteractsWithActionEvent.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Concerns;
|
||||
|
||||
use Laravel\Nova\Actions\ActionResource;
|
||||
|
||||
trait InteractsWithActionEvent
|
||||
{
|
||||
/**
|
||||
* Get the configured ActionResource class.
|
||||
*
|
||||
* @return class-string<\Laravel\Nova\Actions\ActionResource>
|
||||
*/
|
||||
public static function actionResource()
|
||||
{
|
||||
return config('nova.actions.resource') ?? ActionResource::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new instance of the configured ActionEvent.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|\Laravel\Nova\Actions\ActionEvent
|
||||
*/
|
||||
public static function actionEvent()
|
||||
{
|
||||
return static::actionResource()::newModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the callback with an instance of the configured ActionEvent if it is available.
|
||||
*
|
||||
* @param callable(\Laravel\Nova\Actions\ActionEvent):mixed $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public static function usingActionEvent(callable $callback)
|
||||
{
|
||||
if (! is_null(config('nova.actions.resource'))) {
|
||||
return call_user_func($callback, static::actionEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
51
nova/src/Concerns/InteractsWithEvents.php
Normal file
51
nova/src/Concerns/InteractsWithEvents.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Concerns;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Laravel\Nova\Events\NovaServiceProviderRegistered;
|
||||
use Laravel\Nova\Events\ServingNova;
|
||||
|
||||
trait InteractsWithEvents
|
||||
{
|
||||
/**
|
||||
* Register an event listener for the Nova "booted" event.
|
||||
*
|
||||
* @param (\Closure(\Laravel\Nova\Events\NovaServiceProviderRegistered):(void))|string $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function booted($callback)
|
||||
{
|
||||
Event::listen(NovaServiceProviderRegistered::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event listener for the Nova "serving" event.
|
||||
*
|
||||
* @param (\Closure(\Laravel\Nova\Events\ServingNova):(void))|string $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function serving($callback)
|
||||
{
|
||||
Event::listen(ServingNova::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the persistent Nova state.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function flushState()
|
||||
{
|
||||
static::$rtlCallback = null;
|
||||
static::$createUserCallback = null;
|
||||
static::$createUserCommandCallback = null;
|
||||
static::$dashboards = [];
|
||||
static::$jsonVariables = [];
|
||||
static::$resources = [];
|
||||
static::$resourcesByModel = [];
|
||||
static::$scripts = [];
|
||||
static::$styles = [];
|
||||
static::$tools = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user