Issue Checking if variables exist on database

Posted 3 months ago by chrisgrim

Hi, I want to check if a bunch of variables exist on multiple events on a database. I created a public function on my events.php

public function isCompleted()
    {
        $attributes = ['eventTitle','eventDescription','eventWebsite','eventPrice','eventTicketUrl','eventCity','slug','eventImagePath','thumbImagePath','user_id', 'category_id', 'organizer_id', 'eventExpectations', 'immersiveScore'];
        foreach ($attributes as $attribute) {
        if (empty($this->$attribute)) {
            return false;
            }
            return true;
        }
    }

and I am trying to apply this to my index on my eventscontroller

$events = Event::all()->isCompleted()->get();
        return view('events.approval.index', compact('events'));

This gives me the error

"Call to undefined method Illuminate\Database\Eloquent\Builder::isCompleted()"

I believe this is because I am calling isCompleted method on the all() but I am struggling to understand how I would call the method. It seems to sorta work if I do a single event

events = Event::first()->isCompleted()->get();

it gives me an error about "Call to a member function get() on boolean" but that tells me it is working. How would I filter my events in the controller to only those isCompleted()?

Thanks!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.