dimanche 18 septembre 2016

Laravel 5.1 Eloquent - referencing different schema from validation says that schema does not exist

I have a schema called public. Inside this schema I have a table called currencies.

<?php
declare(strict_types=1);

namespace Lapis\Domain\Currency;

use Lapis\Domain\Core\Database\Eloquent\Model;
use Lapis\Domain\Training\EloquentTraining;

/**
 * Class EloquentCurrency
 *
 * @package Lapis\Domain\Currency
 */
class EloquentCurrency extends Model implements CurrencyInterface
{
    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'public.currencies';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'symbol',
        'code',
        'decimal_places',
    ];
}

Everything works perfectly due to setting $table as public.currencies. I can perform all CRUD operations through repository or directly in my controller.

What seems to be broken is trying to use exists rule.

In my validator I have:

'name' => [
    'required',
    'exists:public.currencies',
],

This is just an excerpt. Final validation will be much more complex but the issue is that Laravel is unable to see the table when I call it like public.currencies.

Apparently syntax

schema.table

doesn't work. Any ideas why? I can solve this my using custom validation and using custom repository method to check if exists but I wanted to use native method.

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire