Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0
Last updated 2 years ago.
0

Can it perhaps be fixed without ralationships ?

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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;
}
Last updated 2 years ago.
0

this is a beter solution, I would use relationships and the IoC but this is simpler

http://laravel.io/bin/WWvra

(make sure you autoload any extra file you make with either composer or laravel)

Last updated 2 years ago.
0

If $module == null, you will have the same error.

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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 !:)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

lorienhd lorienhd Joined 20 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.