PHP code example of halestar / laravel-drop-in-cms

1. Go to this page and download the library: Download halestar/laravel-drop-in-cms library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

halestar / laravel-drop-in-cms example snippets


    Route::prefix('admin')->group(function()
        { 
            \halestar\LaravelDropInCms\DiCMS::adminRoutes();
        });

    \halestar\LaravelDropInCms\DiCMS::publicRoutes();

Route::prefix('cms')->group(function()
    {
        \halestar\LaravelDropInCms\DiCMS::adminRoutes();
    });

Route::prefix('admin')->middleware('auth')->group(function()
    {
        \halestar\LaravelDropInCms\DiCMS::adminRoutes();
    });

Route::prefix('front')->group(function()
{
    \halestar\LaravelDropInCms\DiCMS::publicRoutes();
});

'policies' =>
[
    \halestar\LaravelDropInCms\Models\Site::class => env('DICMS_SITE_POLICY', \halestar\LaravelDropInCms\Policies\SitePolicy::class),
    \halestar\LaravelDropInCms\Models\Header::class => env('DICMS_HEADER_POLICY', \halestar\LaravelDropInCms\Policies\HeaderPolicy::class),
    \halestar\LaravelDropInCms\Models\Footer::class => env('DICMS_FOOTER_POLICY', \halestar\LaravelDropInCms\Policies\FooterPolicy::class),
    \halestar\LaravelDropInCms\Models\CssSheet::class => env('DICMS_CSS_SHEET_POLICY', \halestar\LaravelDropInCms\Policies\CssSheetPolicy::class),
    \halestar\LaravelDropInCms\Models\JsScript::class => env('DICMS_JS_SCRIPT_POLICY', \halestar\LaravelDropInCms\Policies\JsScriptPolicy::class),
    \halestar\LaravelDropInCms\Models\Page::class => env('DICMS_PAGE_POLICY', \halestar\LaravelDropInCms\Policies\PagePolicy::class),
    \halestar\LaravelDropInCms\Models\Menu::class => env('DICMS_MENU_POLICY', \halestar\LaravelDropInCms\Policies\MenuPolicy::class),
],

class SitePolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user = null): bool
{
return true;
}

/**
 * Determine whether the user can view the model.
 */
public function view(User $user = null, Site $site = null): bool
{
    return true;
}

/**
* Determine whether the user can create models.
*/
public function create(User $user = null): bool
{
    return true;
}
...

class MySitePolicy extends \halestar\LaravelDropInCms\Policies\SitePolicy
{
    public function create(User $user = null): bool
    {
        return $user->can('create sites');
    }
}

'policies' =>
    [
        \halestar\LaravelDropInCms\Models\Site::class => env('DICMS_SITE_POLICY', \App\Policies\MySitePolicy::class),
        ...
    ],

DICMS_SITE_POLICY=\App\Policies\MySitePolicy::class

// This will actually generate a backup instance. So long as 
// this object persist in memory, you have a snapshot of your 
// database at the time this command is executed.
$backup = new SystemBackup();
// to access the backup data, get it by doing:
$backupData = $backup->getBackupData();
// $backupData now has a string containing all the information
// in your database 

SystemBackup::restore($backupData);

php artisan dicms:backup-cms

php artisan dicms::backup-cms --file=file_out.json 

public function cleanUpDb()
{
    // save the cms data.
    $cmsSave = new SystemBackup();
    $cmsData = $cmsSave->getBackupData();
    // refresh the db, and seed it since it will probably have demo data
    $this->call('migrate:fresh', ['--seed' => true]);
    // restore the CMS data
    $cmsSave->restore($cmsData);
    // Optimize some stuff
    $this->call('optimize:clear');
    $this->call('optimize');
}