daltonmccleery/laravel-quick-start

This package is abandoned and no longer maintained. No replacement package was suggested.

Quick Start package to get up and running with a pre-defined Laravel Structure

v0.1.2 2022-01-31 18:24 UTC

README

Requirements

This package is dependent on some 3rd party Laravel Nova packages, outlined below, so you must have Nova installed and configured prior to installing this package.

Installation

Install this package via Composer:

composer require daltonmccleery/laravel-quick-start

Publish all package assets into your application:

php artisan vendor:publish --provider="DaltonMcCleery\LaravelQuickStart\LaravelQuickStartServiceProvider" --force

Then, run the new migrations:

php artisan migrate

Laravel Nova

Update your NovaServiceProvider to include the following changes:

/**
 * Register the application's Nova resources.
 *
 * @return void
*/
protected function resources()
{
    Nova::resourcesIn(app_path('Nova'));

    Nova::resources([
        \DaltonMcCleery\LaravelQuickStart\Nova\Page::class,
        \DaltonMcCleery\LaravelQuickStart\Nova\Redirect::class,
        \DaltonMcCleery\LaravelQuickStart\Nova\MainNavMenu::class,
        \DaltonMcCleery\LaravelQuickStart\Nova\BannerPromos::class,
        \DaltonMcCleery\LaravelQuickStart\Nova\MobileNavMenu::class,
        \DaltonMcCleery\LaravelQuickStart\Nova\FooterNavMenu::class,
        \DaltonMcCleery\LaravelQuickStart\Nova\ReusableBlocks::class
    ]);
}

Redirects

Update your Http/Kernal.php to add the following line as the last entry in the $middleware array:

protected $middleware = [
    // ...
    \DaltonMcCleery\LaravelQuickStart\Http\Middleware\RedirectRequests::class,
];

Model Revisions

To include Revisional history of changes, add the following Trait to your Model:

use DaltonMcCleery\LaravelQuickStart\Traits\HasModelRevisions;

class YourModel extends Model
{
    use HasModelRevisions;

If you're using Nova, you'll need to update your Model's boot method as follows:

use DaltonMcCleery\LaravelQuickStart\Traits\HasModelRevisions;

class YourModel extends Model
{

    /**
     * The "booted" method of the model.
     *
     * @return void
     */
    protected static function booted()
    {
        static::updating(function ($model) {
            if ($model->create_new_revision) {
                $model = self::create_static_revision($model);
            }
        });
    }

Next, add a checkbox field to that Model's Nova resource, like so:

Boolean::make('Create New Revision', 'create_new_revision')
    ->trueValue(1)
    ->falseValue(0)
    ->hideFromDetail()->hideFromIndex()->hideWhenCreating()
    ->help('Create a new revision upon saving that can be reverted to at any time.')
    ->rules('nullable')

Lastly, you can add a Nova Action to your Model resource for reverting to a specific revision:

use DaltonMcCleery\LaravelQuickStart\Nova\Actions\RevertRevision;

public function actions(Request $request)
{
    return [
        new RevertRevision($request->resourceId, $this)
    ];
}

Now you can create new revisions either statically (via static model closures) or non-statically

self::create_static_revision($model);

$this->create_revision($model);

You can also rollback to the latest revision, or specify an ID of a revision:

$model->revert_last_revision();

$model->revert_to_revision(1);

Routing

By default, the package will autoload the catch-all routes, which will override your application's routes in the web.php file. You may disable the auto-routing via the published config file and manually load the routes by adding the following line in your RouteServiceProvider's boot method:

Route::middleware('web')
    ->namespace($this->namespace)
    ->group(base_path('routes/web.php'));

// Add...
\DaltonMcCleery\LaravelQuickStart\LaravelQuickStartServiceProvider::registerRoutes();

Built With

License

The MIT License (MIT). Please see License File for more information.