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

You should elaborate on the "this doesn't work".

Last updated 2 years ago.
0

Sorry, I get an:

#ErrorException

#Use of undefined constant MyModelName - assumed 'MyModelName'

It crashes on there line where I put $history = MyModelName;

Normally, I would do this:

#$history = MyModelName::where($ary[0],$ary[1],$ary[2])

but I can't in this circumstance because I don't have any definite knowledge of which of the search params will be coming thru.

Wade

Last updated 2 years ago.
0
$history = new MyModelName;
Last updated 2 years ago.
0

Yep, you need to create a new instance of your model.

Last updated 2 years ago.
0

Ok, dum dum on my part. I did that, but now I'm not getting valid data yet.

$history = new MyModelName;
$history->where('content','like','%test%');
$history->get();
print_r($history);

Returns a null array. However, if I do this:

print_r(MyModelName::where('content','like','%test%')->get());

I receive a full data set of my two test records.

Wade

Last updated 2 years ago.
0

@wwendorf

$history->where('content','like','%test%'); // fixed '%test'%
Last updated 2 years ago.
0

Not sure what you mean. My line was correct.

Anyway, I figured out the problem.

The below line works.

$history = new MyModelName;
$history->where('content','like','%test%');
$tmp = $history->get();
print_r($tmp);

This also works:

$history = new MyModelName;
$history->where('content','like','%test%');
print_r($history->get());

Thanks for the help everyone.

Wade

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

wwendorf wwendorf Joined 25 Apr 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.