Can it perhaps be fixed without ralationships ?
Looks like you are using your Model as some sort of Repository
I think it would be easier for you to create a separate CategoryRepository and use that one in your controllers / views.
Relationships between your models like Ruk33 suggested would also benefit you
You could do something like:
public static function GetCategoriesByModule($module)
{
$categories = array();
$tblmodule = tblmodule::where("name", "=", $module)->first();
if ( $tblmodule )
{
$categories = tblcategories::where("module", "=", $tblmodule->id)->get();
}
return $categories;
}
this is a beter solution, I would use relationships and the IoC but this is simpler
(make sure you autoload any extra file you make with either composer or laravel)
If $module == null, you will have the same error.
Ruk33 said:
If $module == null, you will have the same error.
yes and isEmtpy() will also break on a non object, this is just an example
Thanks for the replies! I'm trying both things out now:)
Though, the module can never be null in my case :) so that woudn't be a problem
Fixed it, quick n dirty but it got fixed
I've put an if/else statement around the $linkedCategory checking "if it exists continue, else leave empty"
Thanks for the help zenry and ruk33 !:)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community