Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot install #136

Open
yungifez opened this issue Sep 30, 2022 · 11 comments
Open

Cannot install #136

yungifez opened this issue Sep 30, 2022 · 11 comments

Comments

@yungifez
Copy link

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()
@yungifez
Copy link
Author

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

@tuvshinjargal
Copy link

The same issue happened.

@geimsdin
Copy link

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.

@geimsdin
Copy link

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.

@HansSchouten
Copy link
Owner

HansSchouten commented Oct 13, 2022

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.

@HansSchouten HansSchouten pinned this issue Oct 13, 2022
@yungifez
Copy link
Author

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

@l3bel
Copy link

l3bel commented Oct 23, 2022

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

@Sarthakj02
Copy link

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?

@CristobalNyram
Copy link

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

@CristobalNyram
Copy link

@qaisarshabbir
Copy link

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

@github-staff github-staff deleted a comment Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants