lundi 28 novembre 2016

Trying to get a relationship between legacy tables. - Laravel 5.3 Eloquent

I am trying to sort out a legacy system and I cannot change the field or table names.

I have a table customers and a model in a subdirectory of App\prodec\common. At the start of the model I have placed

namespace App\prodec\common;
use Illuminate\Database\Eloquent\Model;
use \Illuminate\Support\Facades\DB;

class Customer extends Model
{
    protected $table = 'customers';
    protected $primaryKey = 'Reference';
    public $timestamps = false;
    protected $connection = 'common';

    public function country()
        {
            return $this->hasOne('\App\prodec\common\Country','entry','country');
        }

the Country model is

namespace App\prodec\common;

use Illuminate\Database\Eloquent\Model;

class Country extends Model
{
    protected $table = 'countries';
    protected $primaryKey = 'entry';
    public $timestamps = false;
    protected $connection = 'common';


public function customers()
    {
        return $this->hasMany('\App\prodec\common\Customer','entry','country');
    }
}

So customers is indexed by Reference and has a number field for the country of country, and countries is indexed by entry

I am trying to get a list of customers with their appropriate customers from a CommonController

<?php

namespace App\Http\Controllers\prodec\common;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\prodec\common\Customer;

class CommonController extends Controller
{
    public function index()
        {
            return view('prodec.index');
        }

    public function customers()
        {
        $thecustomers = new Customer();
        $customers = $thecustomers->country()->get();
        return view('prodec.customers.index',['customers'=>$customers]);
    }

}

but all I get is a blank with the following in the log

local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class '\App\prodec\common\Country' not found' in D:\Laravel\tdbforge\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:723



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

Aucun commentaire:

Enregistrer un commentaire