> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laravelshopper.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Legal

> As with any e-commerce site, it is important for users to know the terms and conditions and privacy policy that your site offers. This is for their own safety and yours as well.

<Warning>
  This is documentation for Shopper v1, which is no longer maintained. Please refer to the [v2 docs](/v2) for the latest information.
</Warning>

This section allows you to set up your pages for your privacy policy, return policy, terms of use and shipping policy to be presented to customers.

## Fields

The model used is `Shopper\Core\Models\Legal`.

| Name         | Type     | Required | Notes                                                      |
| ------------ | -------- | -------- | ---------------------------------------------------------- |
| `id`         | autoinc  |          | auto                                                       |
| `title`      | string   | yes      | Unique, title of the legal page                            |
| `slug`       | string   | yes      | Unique, this is dynamically generated based on the title   |
| `content`    | longText | no       | nullable, the text of the legal page                       |
| `is_enabled` | boolean  | no       | Default `false`, define if this legal page is ready to use |

## Components

The components used to manage Legal page are found in the component configuration file `config/shopper/components.php`. Each component corresponds to the page that is defined

```php theme={null}
use Shopper\Http\Livewire\Components;

return [
    'livewire' => [

        'settings.legal.privacy' => Components\Settings\Legal\Privacy::class,
        'settings.legal.refund' => Components\Settings\Legal\Refund::class,
        'settings.legal.shipping' => Components\Settings\Legal\Shipping::class,
        'settings.legal.terms' => Components\Settings\Legal\Terms::class,

    ];

];
```

## Add Legal content

In your administration area you must click on the "cog" icon to display the settings page of your store.

* From your admin panel, on the blue sidebar click on the cog icon, go to `Settings > Legal`.

<Frame caption="Settings > Legal">
  <img src="https://mintcdn.com/shopperlabs-ee054f5e/6wDmKBjBTMPmRNSb/images/v1/settings-legal.png?fit=max&auto=format&n=6wDmKBjBTMPmRNSb&q=85&s=1839f9845126f22326fc23d5ea243ec1" alt="legal setting" width="1194" height="567" data-path="images/v1/settings-legal.png" />
</Frame>

Once in this page, all the legal pages are displayed as a tab. You can just fill in the content of each page and click on the Enable switch to retrieve the content of your page and display it in your front-end.

<Frame caption="Legal pages">
  <img src="https://mintcdn.com/shopperlabs-ee054f5e/jlpf_1VxeBnlQtP6/images/v1/legal-screenshot.png?fit=max&auto=format&n=jlpf_1VxeBnlQtP6&q=85&s=1e538cb499f132f0aa9599a4b327094e" alt="legal pages" width="1237" height="616" data-path="images/v1/legal-screenshot.png" />
</Frame>

<Warning>
  Shopper does not generate the routes for the legal pages, you should set them up yourself. As mentioned in the introduction of this documentation, the **Framework** is just an e-commerce administration
</Warning>

## Retrieve Data

Once the information is filled in, we can display it to our users in the views we have created.

To do this we will start by creating a controller that will take care of collecting our information and send it to a view

```bash theme={null}
php artisan make:controller LegalController
```

We will add the functions for each of our pages and return the information to present them to our users. Our controller will look like this

```php theme={null}
namespace App\Http\Controllers;

use Shopper\Core\Models\Legal;

class LegalController extends Controller
{
    public function privacy()
    {
        return view('legal.privacy', [
            'legal' => Legal::enabled()->where('slug', 'privacy-policy')->first(),
        ]);
    }

    public function refund()
    {
        return view('legal.refund', [
            'legal' => Legal::enabled()->where('slug', 'refund-policy')->first(),
        ]);
    }

    public function terms()
    {
        return view('legal.terms', [
            'legal' => Legal::enabled()->where('slug', 'terms-of-use')->first(),
        ]);
    }

    public function shipping()
    {
        return view('legal.shipping', [
            'legal' => Legal::enabled()->where('slug', 'shipping-policy')->first(),
        ]);
    }
}
```

`Legal::enabled()` is a scope to retrieve the page only when it is available. This is a simple way to retrieve the pages but you can do it otherwise all the front-end code depends on you. To learn more about the scopes you can consult the [documentation](https://laravel.com/docs/10.x/eloquent#local-scopes).

### Routes

Once we have created the controllers we will associate the routes that will allow us to display our contents. We will display our content in the `web.php`.

```php theme={null}
use App\Http\Controllers\LegalController;

/*
* Legal routes
*/
Route::get('/privacy', [LegalController::class, 'privacy'])->name('legal.privacy');
Route::get('/terms-of-use', [LegalController::class, 'terms'])->name('legal.terms');
Route::get('/refund-policy', [LegalController::class, 'refund'])->name('legal.refund');
Route::get('/shipping', [LegalController::class, 'shipping'])->name('legal.shipping');
```

### Views

You can create views in this way to arrange the content of your legal pages.

```files theme={null}
resources/views/legal/
    privacy.blade.php
    terms.blade.php
    refund.blade.php
    shipping.blade.php
```

<Info>
  It's just an idea of how to make your views, not a recommendation. If your front-end is in react, vue or svelte you will not necessarily have the same architecture. So keep in mind that it's just to display your content.
</Info>

Example of a view

```blade theme={null}
@extends('layouts.app')

@section('body')

    <x-legal-layout>
        <x-slot name="title">
            <h2 className="text-2xl font-bold uppercase text-dark tracking-wider font-heading sm:text-3xl">
                {{ __('Privacy Policy') }}
            </h2>
            <span className="text-sm leading-5 text-gray-500">{{ __('Last update: :date', ['date' => $legal->created_at->format('d, F Y')]) }}</span>
        </x-slot>

        {!! $legal->content  !!}

    </x-legal-layout>

@endsection
```
