1. Go to this page and download the library: Download glhd/laravel-prismoquent 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/ */
glhd / laravel-prismoquent example snippets
class Page extends \Galahad\Prismoquent\Model
{
// Automatically inferred from class name ("page") if left unset
protected $type;
// Cast RichText to text or HTML (all other cast types also supported)
protected $casts = [
'title' => 'text',
'body' => 'html',
];
// Resolve links as though they were relationships
public function authorLinkResolver() : ?Person
{
return $this->hasOne('author', Person::class);
}
// Also supports repeating groups of links
public function similarPagesLinkResolver()
{
return $this->hasMany('similar_pages.page', static::class);
}
}
class PageController extend Controller
{
public function show(Page $page)
{
return view('page.show', compact('page'));
}
}
// Familiar API
$page = Page::where('document.id', 'W2N5Dx8AAD1TPaYt')->first();
$page = Page::find('W2N5Dx8AAD1TPaYt');
$page = Page::findOrFail('W2N5Dx8AAD1TPaYt');
echo "<h1>{$page->title}</h1>";
echo $page->body;
echo "<p>Written by {$page->author->name}</p>"
echo "<h2>Similar Pages</h2>";
foreach ($page->similar_pages as $similar_page) {
echo "<h3>{$similar_page->title}</h3>";
echo "<p>{$similar_page->meta_description}</p>";
}
// With full support for all Prismic predicates
Page::where('my.page.body', 'fulltext', 'laravel')->get();
return [
'prismic' => [
'endpoint' => env('PRISMIC_ENDPOINT'), // Required
'api_token' => env('PRISMIC_API_TOKEN'), // Optional, depending on your Prismic permissions
'webhook_secret' => env('PRISMIC_WEBHOOK_SECRET'), // Optional, if you're using build-in controller
'register_controller' => false, // Set to false to disable Webhook controller
]
];
// In your AppServiceProvider
Prismic::registerResolver('page', 'pages.show');
Prismic::registerResolver('person', function(DocumentLink $link) {
return url('/people/'.$link->getUid());
});
// In your web.php route file
Route::get('/pages/{page}', 'PageController@show')->name('pages.show');
$html = Prismic::asHtml($fragment);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.