Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nicho's avatar
Level 1

Laravel : the review page error

Hi, i'm currently now developing a website, and i'm trying to create a review page, for user to give a review, but when i tried the review page, it give me this error : Non-static method Modules\Tour\Models\Tour::find() should not be called statically. It's on the ReviewController line 35 : $module = $module_class::find($service_id); How do i fix this error?? The ReviewController :

public function addReview(Request $request,$is_return = false)
    {
        $service_type = $request->input('review_service_type');
        $service_id = $request->input('review_service_id');
        $review_upload = $request->input('review_upload', []);

        $allServices = get_bookable_services();

        if (empty($allServices[$service_type])) {
            if($is_return){
                return $this->sendError(__("Service type not found"));
            }else{
                return redirect()->to(url()->previous() . '#review-form')->with('error', __('Service type not found'));
            }
        }

        $module_class = $allServices[$service_type];
        $module = $module_class::find($service_id);
        if(empty($module)){
            if($is_return){
                return $this->sendError(__("Service not found"));
            }else{
                return redirect()->to(url()->previous() . '#review-form')->with('error', __('Service not found'));
            }
        }

        $reviewEnable = $module->getReviewEnable();
        if (!$reviewEnable) {
            if($is_return){
                return $this->sendError(__("Review not enable"));
            }else{
                return redirect()->to(url()->previous() . '#review-form')->with('error', __('Review not enable'));
            }
        }
        $reviewEnableAfterBooking = $module->check_enable_review_after_booking();
        if (!$reviewEnableAfterBooking) {
            if($is_return){
                return $this->sendError(__("You need booking before write a review"));
            }else{
                return redirect()->to(url()->previous() . '#review-form')->with('error', __('You need booking before write a review'));
            }
        }else{
            if (!$module->check_allow_review_after_making_completed_booking() ) {
                if($is_return){
                    return $this->sendError(__("You can review after making completed booking"));
                }else{
                    return redirect()->to(url()->previous() . '#review-form')->with('error', __('You can review after making completed booking'));
                }
            }
        }

        if ($module->create_user == Auth::id()) {
            if($is_return){
                return $this->sendError(__("You cannot review your service"));
            }else{
                return redirect()->to(url()->previous() . '#review-form')->with('error', __('You cannot review your service'));
            }
        }

        $rules = [
            'review_title'   => 'required',
            'review_content' => 'required|min:10'
        ];
        $messages = [
            'review_title.required'   => __('Review Title is required field'),
            'review_content.required' => __('Review Content is required field'),
            'review_content.min'      => __('Review Content has at least 10 character'),
        ];
        $validator = Validator::make($request->all(), $rules, $messages);
        if ($validator->fails()) {
            if($is_return){
                return $this->sendError($validator->errors());
            }else{
                return redirect()->to(url()->previous() . '#review-form')->withErrors($validator->errors());
            }
        }
        $all_stats = setting_item($service_type."_review_stats");
        $review_stats = $request->input('review_stats');
        $metaReview = [];
        if (!empty($all_stats)) {
            $all_stats = json_decode($all_stats, true);
            $total_point = 0;
            foreach ($all_stats as $key => $value) {
                if (isset($review_stats[$value['title']])) {
                    $total_point += $review_stats[$value['title']];
                }
                $metaReview[] = [
                    "object_id"    => $service_id,
                    "object_model" => $service_type,
                    "name"         => $value['title'],
                    "val"          => $review_stats[$value['title']] ?? 0,
                ];
            }
            $rate = round($total_point / count($all_stats), 1);
            if ($rate > 5) {
                $rate = 5;
            }
        } else {
            $rate = $request->input('review_rate');
        }
        if(setting_item('review_upload_picture') && !empty($review_upload)){
            $metaReview[] = [
                "object_id"    => $service_id,
                "object_model" => $service_type,
                "name"         => 'upload_picture',
                "val"          => json_encode($review_upload)
            ];
        }
        $review = new Review([
            "object_id"    => $service_id,
            "object_model" => $service_type,
            "title"        => $request->input('review_title'),
            "content"      => $request->input('review_content'),
            "rate_number"  => $rate ?? 0,
            "author_ip"    => $request->ip(),
            "status"       => !$module->getReviewApproved() ? "approved" : "pending",
            'vendor_id'     =>$module->create_user
        ]);
        if ($review->save()) {
            if (!empty($metaReview)) {
                foreach ($metaReview as $meta) {
                    $meta['review_id'] = $review->id;
                    $reviewMeta = new ReviewMeta($meta);
                    $reviewMeta->save();
                }
            }
            $images = $request->input('review_upload');
            if(is_array($images) and !empty($images)){
                foreach ($images as $image){
                    if(!$this->validateUploadImage($image)) continue;
                    $review->addMeta('review_image',$image,true);
                }
            }

            $msg = __('Review success!');
            if ($module->getReviewApproved()) {
                $msg = __("Review success! Please wait for admin approved!");
            }
            event(new CreateReviewEvent($module, $review));
            $module->update_service_rate();
            if($is_return){
                return $this->sendSuccess($msg);
            }else{
                return redirect()->to(url()->previous() . '#bravo-reviews')->with('success', $msg);
            }
        }
        if($is_return){
            return $this->sendError( __('Review error!'));
        }else{
            return redirect()->to(url()->previous() . '#review-form')->with('error', __('Review error!'));
        }
    }
0 likes
14 replies
AungHtetPaing__'s avatar

@nicho is your find() static method? The error message telling you are trying to call non-static method with scope resolution operator ::.

Nicho's avatar
Level 1

@Aung Htet Paing__ It looks like this $module = $module_class::find($service_id); so it is static but when i tried on to other project it build fine

AungHtetPaing__'s avatar

@Nicho yes i see that line. But the error is saying it is non-static and i don't know what is inside $allServices. So i think you need to check

$allServices = get_bookable_services(); // do you get data that you require and is it helper method like redirect()? or another method inside reviewcontroller? 
Nicho's avatar
Level 1

@Aung Htet Paing__ So the get_bookable_services(); is work like this

function get_bookable_services()
{

    $all = [];
    // Modules
    $custom_modules = \Modules\ServiceProvider::getModules();
    if (!empty($custom_modules)) {
        foreach ($custom_modules as $module) {
            $moduleClass = "\Modules\" . ucfirst($module) . "\ModuleProvider";
            if (class_exists($moduleClass)) {
                $services = call_user_func([$moduleClass, 'getBookableServices']);
                $all = array_merge($all, $services);
            }
        }
    }


    // Plugin Menu
    $plugins_modules = \Plugins\ServiceProvider::getModules();
    if (!empty($plugins_modules)) {
        foreach ($plugins_modules as $module) {
            $moduleClass = "\Plugins\" . ucfirst($module) . "\ModuleProvider";
            if (class_exists($moduleClass)) {
                $services = call_user_func([$moduleClass, 'getBookableServices']);
                $all = array_merge($all, $services);
            }
        }
    }

    // Custom Menu
    $custom_modules = \Custom\ServiceProvider::getModules();
    if (!empty($custom_modules)) {
        foreach ($custom_modules as $module) {
            $moduleClass = "\Custom\" . ucfirst($module) . "\ModuleProvider";
            if (class_exists($moduleClass)) {
                $services = call_user_func([$moduleClass, 'getBookableServices']);
                $all = array_merge($all, $services);
            }
        }
    }

    return $all;
}
AungHtetPaing__'s avatar

@Nicho do you get data that return from get_bookable_services() in reviewcontroller? Sorry I can't find error.

Nicho's avatar
Level 1

@Aung Htet Paing__ No, i didn't get any data, and just send that error. With the debugger on the error is non-static method, but when the debugger is off it's just error 500

kokoshneta's avatar

@Nicho That’s always the case. When you turn off the debugger, any error will cause a 500 Server Error response.

And you didn’t answer the very first question: is the find() method static or not? We can see that you’re calling it as a static method, but if your \Modules\Tour\Models\Tour class defines it as public function find() instead of public static function find(), when the method itself is not static and you will get this error.

Nicho's avatar
Level 1

@kokoshneta The find() function in the Modules\Tour\Models\Tour is not static method. it public function find()

kokoshneta's avatar

@Nicho Well, that’s the problem, then. You cannot call a non-static method statically.

If you want to be able to use it the same way you use the find() methods in normal Laravel models (ModelClass::find()), then it has to be a static method, and obviously you can’t use $this anywhere inside it.

Nicho's avatar
Level 1

@kokoshneta Ok, so i tried to call the ModelClass::find which is Tour::find() it doesn't work, so i change the find() function to public static function find(), and it gives me error 503

AungHtetPaing__'s avatar

@Nicho Actually if your Tour is the model class generated by Laravel you don't need to change find() method to public static function find(). It works out of the box. But seem like you are doing it manually. Did your non-static method error solved? If it is solved, 503 is another problem.

Nicho's avatar
Level 1

@Aung Htet Paing__ I think it's solved because when the debugger is on the error has change, 503 error

AungHtetPaing__'s avatar

@Nicho If it's solved, mark this as solved and you need to tell more about 503 error. May be other people can help you.

Please or to participate in this conversation.