lundi 23 novembre 2015

How to extend and modify a vendor model in Laravel 5?

I am working with a package antonioribeiro/firewall in my Laravel 5 application and I am using the database to store the list of IP addresses to be blocked.

I have installed it successfully and I am able to use the PragmaRX\Firewall\Vendor\Laravel\Models\Firewall model that it comes with too.

The problem that I have is that I am working with a multi tenant database where basically every tenant has their own database and the models for these tenants use the $connection property to specify the tenant connection and behind the scenes I change the tenant connection config accordingly to the request.

Now the model that comes with package looks like so:

<?php namespace PragmaRX\Firewall\Vendor\Laravel\Models;
/**
 * Part of the Firewall package.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the 3-clause BSD License.
 *
 * This source file is subject to the 3-clause BSD License that is
 * bundled with this package in the LICENSE file.  It is also available at
 * the following URL: http://ift.tt/1jPRlJS
 *
 * @package    Firewall
 * @author     Antonio Carlos Ribeiro @ PragmaRX
 * @license    BSD License (3-clause)
 * @copyright  (c) 2013, PragmaRX
 * @link       http://pragmarx.com
 */

use Illuminate\Database\Eloquent\Model as Eloquent;

class Firewall extends Eloquent {

    protected $table = 'firewall';

    protected $guarded = array();

}

I added protected $connection = 'tenant'; to it to make it work but I am editing vendor files which won't show up in the version control. So being a novice developer I am trying to figure out how to extend this model somehow and then put the $connection property.

I tried creating a new model in the App namespace and extended the model that comes with the package but in vain.

So how do I extend the model that comes with the package to add to it so that it shows up in the version control and I am not editing vendor files?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1I7GDOJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire