# Blog

## Post

<!-- panels:start -->
<!-- div:title-panel -->
### List
<!-- div:left-panel -->


Get all content with paginate.

> [!NOTE]
> **Parameters**<br>
> - **paginate**
>   - **Type:** Integer
>   - **Default:** 10
>   - **Required:** false

?> **Response Type:** Illuminate\Support\Collection<br>
**Response Content:** App\Models\Posts


<!-- div:right-panel -->


<!-- tabs:start -->

#### **Code**

```php
get_blogs($paginate = 10)
```

#### **Example**

```php
@foreach (get_blogs(3) as $post)
    <div class="col-sm-9 col-md-6 col-lg-4 mb-4 mb-lg-0">
        <a href="{{ url('blog/'.$post->content->url) }}" class="text-decoration-none" data-cursor-effect-hover="plus">
            <div class="card border-0">
                <div class="card-img-top position-relative overlay">
                    <div class="position-absolute bottom-10 right-0 d-flex justify-content-end w-100 py-3 px-4 z-index-3">
                        <span class="text-center bg-primary text-color-light font-weight-semibold text-5-5 line-height-2 px-3 py-2">
                            <span class="position-relative z-index-2">
                                {{ $post->created_at->format('d') }}
                                <span class="d-block custom-font-size-1 positive-ls-2 px-1">{{ $post->created_at->format('M') }}</span>
                            </span>
                        </span>
                    </div>
                    <img src="{{ Common::get_post_original_image($post->id, $post->image, 'large') }}" class="img-fluid" alt="Lorem Ipsum Dolor" />
                </div>
                <div class="card-body py-4 px-0">
                    <h3 class="text-transform-none font-weight-bold text-5 text-color-hover-primary mb-2">{{ $post->content->title ?? '' }}</h3>
                    <span class="custom-view-more d-inline-flex font-weight-medium text-color-primary">
                        {{ __('Daha Fazla') }}
                        <img width="27" height="27" src="{{ get_asset('img/demos/construction/icons/arrow-right.svg') }}" alt="" data-icon data-plugin-options="{'onlySVG': true, 'extraClass': 'svg-fill-color-primary ms-2'}" style="width: 27px;" />
                    </span>
                </div>
            </div>
        </a>
    </div>
@endforeach
```

#### **Inspect**

```php
function get_blogs($paginate = 10)
{
    $query = Posts::with('content', 'category')->whereHas('content')->orderBy('created_at', 'DESC')->paginate($paginate);
    return $query;
}
```

<!-- tabs:end -->


<!-- panels:end -->



<!-- panels:start -->
<!-- div:title-panel -->
### Media
<!-- div:left-panel -->
Get blog post media.

> [!NOTE]
> **Parameters**<br>
> - **blogId**
>   - **Type:** Integer (\App\Models\Posts)
>   - **Default:** -
>   - **Required:** true
> - **image**
>   - **Type:** String
>   - **Default:** -
>   - **Required:** true


?> **Response Type:** Illuminate\Support\Str<br>
**Response Content:** Media path

<!-- div:right-panel -->

<!-- tabs:start -->

#### **Code**

```php
get_blog_media($blogId, $image)
```

#### **Example**

```php
@foreach ($post->images as $item)
    @php $i++; @endphp
    <tr class="image_{{ $item->id }}" data-id="{{ $item->id }}">
        <td><span style="background-color: #eee; padding: 20px; font-weight: bold;"
                class="d-inline-block">{{ $i }}</span>
        </td>
        <td style="padding: 20px;">
            <a href="{{ get_blog_media($post->id, $item->name) }}"
                target="_blank" class="item-img">
                @if (checkImage($item->name))
                    <img src="{{ get_blog_media($post->id, $item->name) }}"
                        alt="{{ $post->name }}" height="50">
                @else
                    <video class="card-img-top custom-border-radius-1" controls
                        height="150">
                        <source src="{{ get_blog_media($post->id, $item->name) }}"
                            type="video/mp4">
                    </video>
                @endif
            </a>
        </td>
        <td>
            <div class="btn-group btn-block" role="group"
                aria-label="editremove">
                <button type="button"
                    class="btn btn-outline-danger btn-sm btn-remove-item"
                    data-id="{{ $item->id }}"
                    data-item-type="post-image">Sil</button>
            </div>
        </td>
    </tr>
@endforeach
```

#### **Inspect**

```php
function get_blog_media($blogId, $image)
{
    $image_path = "uploads/posts_images/" . $blogId . "/" . $image;
    $path = public_path($image_path);
    if (file_exists($path)) {
        return asset($image_path) . "?v=" . date('Y-m-d-H:i');
    } else {
        return asset('images/no_image.png');
    }
}
```

<!-- tabs:end -->

<!-- panels:end -->


---

## Category

Get blog categories.

- Example usage +

    ```php
    @if ( get_blog_categories_main() )
        <div class="col-lg-4 mb-4">
            <h2>{{ __('Kategoriler') }}</h2>

            <div class="list-group">
                @foreach (get_blog_categories_main() as $item)
                    <a href="{{ route('post.category', ['category_url' => ($item->content->url ?? '-')]) }}" class="list-group-item list-group-item-action @if($item->id == $category->id) border border-1 border-primary @endif"><i class="fa fa-angle-right"></i> {{ ($item->content->name ?? '-') }}</a>
                @endforeach
            </div>
        </div>
    @endif
    ```

<!--  -------------------------------------------------------------  -->

<!-- panels:start -->
<!-- div:title-panel -->
### All Categories
<!-- div:left-panel -->

Get all categories with content.

> [!NOTE]
> **Parameters**<br>
> - **paginate**
>   - **Type:** Integer
>   - **Default:** 10
>   - **Required:** false

?> **Response Type:** Illuminate\Support\Collection<br>
**Response Content:** App\Models\PostCategories
<!-- div:right-panel -->

<!-- tabs:start -->

#### **Code**

```php
get_blog_categories($paginate = 10)
```

#### **Inspect**

```php
function get_blog_categories()
{
    $query = PostCategories::with('content', 'sub_categories')->whereHas('content')->orderBy('position', 'DESC')->get();
    return $query;
}
```

<!-- tabs:end -->
<!-- panels:end -->

<!--  -------------------------------------------------------------  -->

<!-- panels:start -->
<!-- div:title-panel -->
### Parent Categories
<!-- div:left-panel -->

Get only parent categories with content.

?> **Response Type:** Illuminate\Support\Collection<br>
**Response Content:** App\Models\PostCategories
<!-- div:right-panel -->

<!-- tabs:start -->

#### **Code**

```php
get_blog_categories_main()
```

### **Example**

```php
@if ( get_blog_categories_main() )
    <div class="col-lg-4 mb-4">
        <h2>{{ __('Kategoriler') }}</h2>

        <div class="list-group">
            @foreach (get_blog_categories_main() as $item)
                <a href="{{ route('post.category', ['category_url' => ($item->content->url ?? '-')]) }}" class="list-group-item list-group-item-action @if($item->id == $category->id) border border-1 border-primary @endif"><i class="fa fa-angle-right"></i> {{ ($item->content->name ?? '-') }}</a>
            @endforeach
        </div>
    </div>
@endif
```

#### **Inspect**

```php
function get_blog_categories_main()
{
    $query = PostCategories::where('parent_id', '=', 0)->with('content', 'sub_categories')->whereHas('content')->orderBy('position', 'DESC')->get();
    return $query;
}
```

<!-- tabs:end -->
<!-- panels:end -->

<!--  -------------------------------------------------------------  -->
