ajsmith_codes
2 months ago
214
2
Laravel

Can't call method from controller.

Posted 2 months ago by ajsmith_codes

I have multiple controllers where I call methods on models like this: $someVariable->callToMethod();

I do this a lot, but I can't get this to work today. I get this error: Property [expedited] does not exist on the Eloquent builder instance.

Controller:

 $order = Order::where('id', $id);

    $expedited = $request->expedited;
    $originalValue = $order->expedited;

    if ($expedited != $originalValue) {
        request('expedited') ? $order->expedited() : $order->notExpedited();
    }

Model:

public function expedited(){

    $this->update(['expedited' => true]);
}

public function notExpedited(){

    $this->update(['expedited' => false]);
}

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