skip to Main Content

I created a custom file named ZibalRequest.php in laravel Controllers directory and here is my file :

<?php

namespace AppHttpControllers;

class ZibalRequest
{


public function sendSmsOtp($amount , $invoice_name , $user_mobile)
{

    return 'boo';
    
}


}

and called it in my controller this way :

        $ee = new ZibalRequest();
    $ee->sendSmsOtp(    $amount,
        $invoice_name,
        $user_mobile
    );

I think I named files and namespaces correctly but I’m getting this error :

Class "AppHttpControllersZibalRequest" not found

What’s wrong with laravel?

2

Answers


  1. Extend controller class in defined controller, Like below

    <?php
    
    namespace AppHttpControllers;
    
    class ZibalRequest extends Controller
    {
    
    
       public function sendSmsOtp($amount , $invoice_name , $user_mobile)
       {
    
        return 'boo';
        
       }
    
    
    }
    
    Login or Signup to reply.
  2. I tried the same code and tested it, and it’s working fine on my side.

    <?php
    namespace AppHttpControllers;
    
    class ZibalRequest
    {
        public static function sendSmsOtp($amount, $invoice_name, $user_mobile)
        {
            return 'boo';
        }
    }
    

    Other Controller where you call the class.

    <?php
    
    namespace AppHttpControllers;
    
    class OtherController extends Controller
    {
      public function index()
        {
            $amount = 10;
            $invoice_name = 'ddd';
            $user_mobile = 1111111;
        
            $ee = new ZibalRequest();
            return  $ee->sendSmsOtp($amount, $invoice_name, $user_mobile);
    
        }
        }
    

    It returns ‘boo’ when I hit the index() method from the router.

    Please share more code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search