php - laravel 5 Query Builder error "must be of the type array, object given" -
ok trying perform mysql query join tables , return results.
so in controller have array of serviceids when print_r() looks this:
array ( [0] => 50707 [1] => 50709 ) the name of array $serviceids
okay call function 1 of models. scope seen below:
$services = services::getwatchlistinfo($serviceids)->get(); this scope function in model:
public function scopegetwatchlistinfo($serviceids){ $services = db::table('services') ->join('reviews','services.serviceid','=','reviews.serviceid') ->select('services.name','services.type','services.review_count_approved','reviews.escalate','reviews.average_rating') ->wherein('serviceid',$serviceids); return $services; } okay should results both services , reviews table service id in array.
instead getting following error.
argument 1 passed illuminate\database\grammar::parameterize() must of type array, object given, called in /users/user/sites/informatics-2/vendor/laravel/framework/src/illuminate/database/query/grammars/grammar.php on line 311 , defined any ideas?
you're not using eloquent scopes correctly. if read docs, you're attempting use dynamic scope, need define scope as:
/** * getwatchlist eloquent scope * * @param object $query * @param array $servicesids * @return object $query */ public function scopegetwatchlistinfo($query, $serviceids = []) { return $query ->join('reviews','services.serviceid','=','reviews.serviceid') ->select('services.name','services.type','services.review_count_approved','reviews.escalate','reviews.average_rating') ->wherein('serviceid', $serviceids); } the db::table('services') should not necessary if you're defining scope within services model (because services table automatically handled eloquent:
now, let's @ example
flightmodel class, use retrieve , store information ourflightsdatabase table
Comments
Post a Comment