PHP code example of gorankrgovic / larablog

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

    

gorankrgovic / larablog example snippets


$article = new Article([
            'title' => 'This is my title',
            'slug' => 'this-is-my-slug',
            'excerpt' => 'This is my excerpt',
            'content' => 'This is my content',
            'is_featured' => false,
            'status' => 'publish',
            'publish_at' => Carbon::now()
]);

// associate the user
$article->associateUser(1);
// save the article
$article->save();

// attach the category
$article->attachCategory('uncategorized'); // name or the ID

// or multiple categories
$article->attachCategories([1, 2, 3]); // names or ID's
 
$article = Article::find(1);

// get the categories (cacheable)
$article->getCategories();

$user = User::find(1);

$articles = $user->getArticles();

// or
$articles = $user->getArticlesPaginated(20);

// or
$articles = $user->articles()->get();
 

$articles = Article::whereCategoriesAre([1, 2, 3])->get(); // pass an array of IDs

// or

$articles = Article::whereCategoryIs(1)->get(); // pass an id

use Gorankrgovic\Larablog\Facades\Larablog;

// ... and then in your methods...

// to generate a unique slug which will append number at the end of the slug if the same slug exists
$slug = Larablog::slug($title);

// to convert string to paragraph delimited text
$text = Larablog::autop($content);

// to generate the excerpt
$excerpt = Larablog::excerpt($content);

// to just sanitize the title and to get a slug
$slug = Larablog::sanitize_title($title);

bash
$ php artisan
bash
$ php artisan vendor:publish --tag="larablog"
bash
$ php artisan larablog:setup
bash
$ php artisan migrate
bash
$ php artisan larablog:seeder
bash
$ php artisan db:seed --class=LarablogSeeder