This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
chris10207
In a component, lets say we want to pull out a product details from the database. our component will look like this
public function onRun() { $this->product = $this->page['product'] = $this->loadProduct(); } public function loadProduct() { return Product::whereSlug($this->slug)->with(['images'])->first(); }
Now my concern is to manage the potentials errors where the slug passed trough the url does not exist in the database. How do we redirect to an error 500 for example or any other page ?
i tried to do like this but it does not go trough
public function loadProduct() { $product = Product::whereSlug($this->slug)->with(['images'])->first(); if(!$product) return $this->controller->run('404'); return $product; }
thanks
1-1 of 1