PHP code example of plank / contentable

1. Go to this page and download the library: Download plank/contentable 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/ */

    

plank / contentable example snippets




namespace App\Models;

use App\Models\Contracts\Renderable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Plank\Contentable\Concerns\CanRender;

class TextModule extends Model implements Renderable
{
    use CanRender;
    use HasFactory;
    
    protected $guarded = ['id'];

    protected array $renderableFields = ['title', 'body'];
    
    public function renderHtml(): string
    {
        return "<h2>{$this->title}</h2>" +
                "<p>{$this->body}</p>";
    }
}



namespace App\Models;

use App\Models\Concerns\HasContent;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Plank\Contentable\Contracts\Contentable;


class Page extends Model implements Contentable
{
    use HasContent;
    use HasFactory;

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = ['id'];
    
    /**
     * Get the route key for the model.
     */
    public function getRouteKeyName(): string
    {
        return 'slug';
    }
}

use Illuminate\Database\Eloquent\Model;
use App\Models\Concerns\HasLayouts;
use Plank\Contentable\Contracts\Contentable;
use Plank\Contentable\Contracts\Layoutable;

class Page extends Model implements Contentable, Layoutable
{
    // ...
    use HasLayouts;
    
    /**
     * (Optional: Allows for layouts to be model specific)
     * Restrict the Page layouts to ones strictly in the Pages folder
     */
    protected static $globalLayouts = false;
}

public function show(Page $page): \Illuminate\View\View
{
    return view($page->layout())->with(compact('page'));
}