HansSchouten/Laravel-Pagebuilder

Cannot install

yungifez opened this issue · 11 comments

I tried installation following the instructions step by step

I cannot migrate because a table cannot be found, but the migration is meant to add the table it is checking for

Temporary fix , migrate before publishing config then change prefix to nothing

 sail artisan migrate
   PDOException 

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.pagebuilder__settings' doesn't exist

  at vendor/hansschouten/phpagebuilder/src/Core/DB.php:65
     61▕             $stmt = $this->pdo->prepare("SELECT {$columns} FROM {$table}");
     62▕         } else {
     63▕             $stmt = $this->pdo->prepare("SELECT * FROM {$table}");
     64▕         }
  ➜  65▕         $stmt->execute();
     66▕         return $stmt->fetchAll();
     67▕     }
     68▕ 
     69▕     /**

      +21 vendor frames 
  22  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}()

      +5 vendor frames 
  28  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

forgot to add

Application Name ......................................................................... Laravel
Laravel Version ........................................................................... 9.32.0
PHP Version ................................................................................ 8.1.9
Composer Version ........................................................................... 2.4.1
Environment ................................................................................ local
Debug Mode ............................................................................... ENABLED
URL .................................................................................... localhost
Maintenance Mode ............................................................................. OFF

Cache ............................................................................................
Config ................................................................................ NOT CACHED
Events ................................................................................ NOT CACHED
Routes ................................................................................ NOT CACHED
Views ..................................................................................... CACHED

Drivers ..........................................................................................
Broadcasting ................................................................................. log
Cache ....................................................................................... file
Database ................................................................................... mysql
Logs .............................................................................. stack / single
Mail ........................................................................................ smtp
Queue ....................................................................................... sync
Session ..................................................................................... file

Im on sail

The same issue happened.

Same problem here, just tried to install on a fresh Laravel 9.3 but seems something is off because it tries to read the table before running the migration.

The fast solution waiting for a fix in the package is to set PDO as silent before migrating, after you can rollback to the default ERROR MODE.

File: vendor/phpageBuilder/hansschouten/src/Core/DB.php

Line 32

Change this:
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]

into this:
[PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]

migrate and then revert the change.

Hope it helps.

I have never used this repo myself, instead I use the core https://github.com/HansSchouten/PHPageBuilder in Laravel instead with some customizations.

In my service provider I create a phpagebuilder singleton:

$this->app->singleton('phpPageBuilder', function ($app) {
    return new PHPageBuilder(config('pagebuilder'));
});
$this->app->make('phpPageBuilder');

I have a controller to edit pages via the pagebuilder:

<?php

namespace Falco\Website\Http\Controllers;

use Falco\Website\Repositories\PageLayoutRepository;
use Illuminate\Http\RedirectResponse;
use Falco\Website\Repositories\PageRepository as Page;
use PHPageBuilder\Contracts\PageContract;
use PHPageBuilder\PHPageBuilder;
use PHPageBuilder\Repositories\PageRepository;
use Throwable;

class PageBuilderController extends Controller
{
    /**
     * Contains route related configuration
     *
     * @var array
     */
    protected $_config;

    /**
     * PageRepository object
     *
     * @var array
     */
    protected $page;

    /**
     * Create a new controller instance.
     *
     * @param Page $page
     * @return void
     */
    public function __construct(Page $page)
    {
        $this->middleware('admin');

        $this->page = $page;

        $this->_config = request('_config');
    }

    /**
     * Edit the given page with the page builder.
     *
     * @param int|null $pageId
     * @throws Throwable
     */
    public function build($pageId = null)
    {
        $route = $_GET['route'] ?? null;
        $action = $_GET['action'] ?? null;

        $pageId = is_numeric($pageId) ? $pageId : ($_GET['page'] ?? null);
        $pageRepository = new PageRepository;
        /* @var PageContract $page */
        $page = $pageRepository->findWithId($pageId);

        /* @var PHPageBuilder $phpPageBuilder */
        $phpPageBuilder = app()->make('phpPageBuilder');
        $pageBuilder = $phpPageBuilder->getPageBuilder();

        $customScripts = view("website::pagebuilder.scripts")->render();
        $pageBuilder->customScripts('head', $customScripts);
        $pageBuilder->handleRequest($route, $action, $page);
    }
}

A controller to render pages:

<?php

namespace Falco\Website\Http\Controllers\Frontend;

use Falco\Website\Http\Controllers\Controller;
use Falco\Website\Libraries\PHPageBuilder\PageRenderer;
use Falco\Website\Repositories\BlogPostRepository;
use Falco\Website\Repositories\PageRepository;
use Falco\Website\Repositories\PageRepository as Page;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use PHPageBuilder\Modules\GrapesJS\Thumb\ThumbGenerator;
use PHPageBuilder\Theme;
use PHPageBuilder\ThemeBlock;
use Carbon\Carbon;
use Exception;

class WebsiteController extends Controller
{
    /**
     * Contains route related configuration
     *
     * @var array
     */
    protected $_config;

    /**
     * PageRepository object
     *
     * @var array
     */
    protected $page;

    /**
     * Create a new controller instance.
     *
     * @param  Page $page
     * @return void
     */
    public function __construct(Page $page)
    {
        $this->page = $page;

        $this->_config = request('_config');
    }

    /**
     * Show the website page that corresponds with the current URI.
     */
    public function uri()
    {
        set_frontend_language_from_url();

        // set datetime language
        setlocale(LC_TIME, 'en_US.utf8');
        if (current_frontend_language() !== 'en') {
            setlocale(LC_TIME, current_frontend_language() . '_' . strtoupper(current_frontend_language()) . '.utf8');
        }
        Carbon::setLocale(current_frontend_language());

        ob_start();
        $pageBuilder = app()->make('phpPageBuilder');
        $pageBuilder->handlePublicRequest();
        $html = ob_get_contents();
        ob_end_clean();

        return response()->make($html, PageRenderer::$statusCode);
    }

    /**
     * Render the theme block that is currently publicly accessible if the given access token matches.
     *
     * @param string $accessToken
     * @throws Exception
     */
    public function renderBlockForThumb(string $accessToken)
    {
        $renderBlockFile = 'render-block-thumbs/current-block.json';
        if (Storage::disk('local')->exists($renderBlockFile)) {
            $content = json_decode(Storage::disk('local')->get($renderBlockFile), true);
            if (! empty($content['access-token']) && $content['access-token'] === $accessToken) {
                $blockSlug = $content['block-slug'];
                $theme = new Theme(config('pagebuilder.theme'), config('pagebuilder.theme.active_theme'));
                $block = new ThemeBlock($theme, $blockSlug);

                $thumbRenderer = new ThumbGenerator($theme);
                $thumbRenderer->renderThumbForBlock($block);
            }
        }

        abort(404);
    }
}

And after all (backend) routes I use a catch-all to render frontend pages:

    Route::group(['middleware' => ['phpagebuilder-session-language']], function () {
        Route::any('{uri}', [
            'uses' => 'Falco\Website\Http\Controllers\Frontend\WebsiteController@uri',
            'as' => 'website.page',
        ])->where('uri', '.*');
    });

Hopefully some day I have time to translate this to the Laravel-Pagebuilder library, but for now I can customize my project easier this way. So if anyone knows a fix for the migration issue feel fry to make a pull request, or if one wants to ommit the Laravel library layer and use PHPageBuilder core instead maybe this might help as well.

I'll see if I can diagnose a fix without changing the main package

l3bel commented

The fast solution waiting for a fix in the package is to set PDO as silent before migrating, after you can rollback to the default ERROR MODE.

File: vendor/phpageBuilder/hansschouten/src/Core/DB.php

Line 32

Change this: [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]

into this: [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]

migrate and then revert the change.

Hope it helps.

Thanks, it works 👍
A small typo in the path, for me it is
vendor/hansschouten/phpagebuilder/src/Core/DB.php

The fast solution waiting for a fix in the package is to set PDO as silent before migrating, after you can rollback to the default ERROR MODE.
File: vendor/phpageBuilder/hansschouten/src/Core/DB.php
Line 32
Change this: [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
into this: [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]
migrate and then revert the change.
Hope it helps.

Thanks, it works +1 A small typo in the path, for me it is vendor/hansschouten/phpagebuilder/src/Core/DB.php

these we can do in local host but want it be difficult to do in server?

Other possible solutions is run in this order the commands

1 composer require hansschouten/laravel-pagebuilder

2 php artisan migrate

3php artisan vendor:publish --provider="HansSchouten\LaravelPageBuilder\ServiceProvider" --tag=config

The fast solution waiting for a fix in the package is to set PDO as silent before migrating, after you can rollback to the default ERROR MODE.

File: vendor/phpageBuilder/hansschouten/src/Core/DB.php

Line 32

Change this: [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]

into this: [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]

migrate and then revert the change.

Hope it helps.

This solution works, the only thing is the DB.php path
New Path: vendor/hansschouten/phpagebuilder/src/Core/DB.php