framework
framework copied to clipboard
Naming/Namespace conflict ?
Why this code is causing the error?
../app/Models/Model.php
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Model extends Eloquent {
protected $table = 'models';
public function brand()
{
return $this->belongsTo('App\Models\Brand', 'brandId');
}
}
../app/Models/Brand.php
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Brand extends Model
{
protected $table = 'brands';
public function models()
{
return $this->hasMany('App\Models\Model', 'brandId');
}
}
Controller:
<?php namespace App\Http\Controllers;
use App\Models\Model;
class IndexController extends Controller
{
public function index()
{
$model = Model::find(1);
dd($model->brand);
}
}
Error: FatalErrorException in Brand.php line 3: Cannot use Illuminate\Database\Eloquent\Model as Model because the name is already in use
You have a class called model, then you try to import something and name it mode. You can't do that.