1. Go to this page and download the library: Download edulazaro/laraindexnow 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/ */
->whenIn('status', ['published', 'featured']) // one attribute, several values
->when(['status' => 'published', 'review' => 'correct']) // several attributes
->whenBecame(['published' => true, 'status' => 'live'])
IndexNow::track(Post::class)
->url(fn (Post $post) => route('blog.show', $post->slug))
->whenBecame('published', true) // it just flipped to true
->when('review', 'correct'); // and this holds right now
->when('published') // published is true
->whenNot('spam') // spam is false
->when('comment_count') // has at least one
->when('comment_count', '>=', 5)
// A game page is worth indexing once it is approved and has playthroughs.
// Either half can be the one that arrives last, so declare both routes.
IndexNow::track(Game::class)
->url('games.show')
->whenLeft('playthroughs', 0) // playthroughs arrived, already approved
->whenHolds('approved', true);
IndexNow::track(Game::class)
->url('games.show')
->whenBecame('approved', true) // approval arrived, playthroughs already there
->when(fn (Game $game) => $game->playthroughs > 0);
->url('blog.show') // route('blog.show', $post)
->url('https://example.com/about') // taken literally
->url('/about') // taken literally
->url(fn (Post $post) => route('blog.show', $post->slug))
use EduLazaro\IndexNow\Policy;
class PostIndexNow extends Policy
{
public function url(Model $post): ?string
{
return route('blog.show', $post->slug);
}
public function when(Model $post): bool
{
return $post->status === PostStatus::Published;
}
}
IndexNow::submit('https://example.com/page'); // buffered, sent by the queue
IndexNow::submit([$urlOne, $urlTwo]);
IndexNow::submitNow($url); // sent inline, returns the results
IndexNow::submitModel($post); // resolves the URL from the registration