Git Product home page Git Product logo

Comments (10)

kousar2334 avatar kousar2334 commented on May 29, 2024 1

it works. thank you so much.

from laravel-pagebuilder.

HansSchouten avatar HansSchouten commented on May 29, 2024

When the $data is rendered it is a full html structure, so I suggest not to pass it to a blade view file since it is already a full webpage. There are multiple ways to render the data from one page, you could do this:

use PHPageBuilder\Theme;
use PHPageBuilder\Modules\GrapesJS\PageRenderer;
use PHPageBuilder\Repositories\PageRepository;

public function viewPage($pageId)
{
	$theme = new Theme(config('pagebuilder.theme'), config('pagebuilder.theme.active_theme'));
	$page = (new PageRepository)->findWithId($pageId);
	$pageRenderer = new PageRenderer($theme, $page);
	$html = $pageRenderer->render();
	return $html;
}

from laravel-pagebuilder.

kousar2334 avatar kousar2334 commented on May 29, 2024

I have copied the function but there is an error.
Error
Call to a member function findWithId() on null
http://127.0.0.1:8000/admin/pages/1

from laravel-pagebuilder.

HansSchouten avatar HansSchouten commented on May 29, 2024

On what line of the code does this error occur? Can you further trace where it went wrong, this error does not reveal to me what causes it.

from laravel-pagebuilder.

kousar2334 avatar kousar2334 commented on May 29, 2024

public function findWithId($id)

{

    return $this->createInstance($this->db->findWithId($this->table, $id));//the error is occur this line

}

Screenshot_2020-06-28_12-40-03

from laravel-pagebuilder.

HansSchouten avatar HansSchouten commented on May 29, 2024

Ok that shows me what is the issue, the DB is not instantiated. This makes sense because this is done when we create a PHPageBuilder instance, which we did not do. I just committed a fix to the master which will be part of the next release.
For now you can add this to the boot method of your App\Providers\AppServiceProvider:

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

from laravel-pagebuilder.

kousar2334 avatar kousar2334 commented on May 29, 2024

Screenshot_2020-06-28_13-08-46
there is an error.

from laravel-pagebuilder.

HansSchouten avatar HansSchouten commented on May 29, 2024

Yes everytime you create an instance of a class that is not inside the current folder, you need to include it with use [namespace]. If you switch to an editor like PhpStorm it warns you of this and helps to fix it. In this case you need to add:

use PHPageBuilder\PHPageBuilder;

from laravel-pagebuilder.

mansmahamat avatar mansmahamat commented on May 29, 2024

public function viewPage($pageId)
{
$data=DB::table('pagebuilder__pages')->where('id',$pageId)->value('data');
return $data;
}
I get the page data from the function, How can I render the data into blade?

When the $data is rendered it is a full html structure, so I suggest not to pass it to a blade view file since it is already a full webpage. There are multiple ways to render the data from one page, you could do this:

use PHPageBuilder\Theme;
use PHPageBuilder\Modules\GrapesJS\PageRenderer;
use PHPageBuilder\Repositories\PageRepository;

public function viewPage($pageId)
{
	$theme = new Theme(config('pagebuilder.theme'), config('pagebuilder.theme.active_theme'));
	$page = (new PageRepository)->findWithId($pageId);
	$pageRenderer = new PageRenderer($theme, $page);
	$html = $pageRenderer->render();
	return $html;
}

Where write this code ?

from laravel-pagebuilder.

HansSchouten avatar HansSchouten commented on May 29, 2024

You can make a Laravel controller method with this snippet.

from laravel-pagebuilder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.