Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:29:29+00:00 2026-06-18T09:29:29+00:00

I have a polymorphic relationship in Laravel 4 and it’s working like I want.

  • 0

I have a polymorphic relationship in Laravel 4 and it’s working like I want. I have another one, which doesn’t work when I try to insert the related model, even though it is identical to the first one and I use it in the same way.

I have Event model and an Article model:

// Article Model
class Article extends Eloquent {
    public function events() {
        return $this->morphMany('Event', 'eventable');
    }
    ...

// Event Model
class Event extends Eloquent {
    public function eventable() {
        return $this->morphTo();
    }
}

Usage:

$article = Article::find($article_id);
// insert
// neither of the following lines work
$article->events()->create(array("type" => "click"));
$article->events()->save(new Event(array("type" => "click")));

I get the same error:

Error: Call to undefined method Illuminate\Support\Facades\Event::newQuery() in
\app_path\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php line 383

What am I doing wrong? I have an identical situation with an Article and it’s Photos, but there it works (it’s also a polymorphic relation).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:29:31+00:00Added an answer on June 18, 2026 at 9:29 am

    Event is likely a reserved word in Laravel. Unless you namespace it, i’d suggest avoiding creating a class called Event, since it is like used in Laravel core. Something like activity could potentially serve as an alternative.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a polymorphic relationship in Rails, but in one particular instance of use,
I have a model Articles that has_many Assets which is a polymorphic model that
I have a tags model that I'd like to be polymorphic, but I don't
I'm working on my first Rails project, and I have the following model relationship:
I have the models Home and Photo, which have a has_many - belongs_to relationship
I want to have a parent child relationship in the same table. Below is
I want to have one model & view that is served by multiple controllers
I am using polymorphic association. I have 2 models articles and events which have
I have a standard polymorphic relationship and I need to know who its parent
A Person can have many Events and each Event can have one polymorphic Eventable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.