In Laravel 4 I want to use a model that represents an Event coming from my database. Thus, in app/models I have my Event model that extends Eloquent.

然而,Laravel 4已经有了一个Event类,用于管理应用程序生命周期内的事件.

What I want to know is, how can I properly namespace my Event model and access it in a way that will not clash with the existing Event class.

推荐答案

你只需要像平常一样给它应用一个名称空间.比如说.

<?php namespace Models;

use Eloquent;

class Event extends Eloquent {

}

You should then correctly setup your composer.json so that it loads your models. You could use classmap or psr-0 for this, depending on whether or not you're following PSR-0 with your directory structure.

I'm pretty sure the models directory is already mapped.

Edit
As mentioned in the comments you must run composer dump-autoload.

Laravel相关问答推荐

try 编写一个函数,如果产品存在,则无法删除特定类别

保存很多模型太慢

在没有lang/*.json文件的情况下在Laravel项目中实现多语言支持

Laravel 联合和分页

在 blade laravel 中以格式编号显示长数字

Laravel 连接表

Laravel API 版本控制文件夹 struct

如何在 laravel 中使用 str_replace

PHP 中的 Http 响应代码枚举

Twilio 查找 API 不起作用?

条带 api 判断现有卡

不支持驱动Driver[] - Laravel 5.3

设置 Laravel 5.4 以使用 React

在 Laravel Eloquent 中,limit 与 take 有什么区别?

调用未定义的方法 Maatwebsite\Excel\Excel::load()

加载模型的所有关系

Select,where JSON 包含数组

如何以 JSON 格式发送 Laravel 错误响应

Laravel 从公共删除目录

在laravel中删除确认