Laravel控制台命令不起作用

时间:2016-05-27 13:14:31

标签: php laravel console

尝试在laravel 5.2上设置一个示例控制台命令,但它无法正常工作

我跑了<?php namespace App\Console\Commands; use Illuminate\Console\Command; class CoolCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'be:cool'; /** * The console command description. * * @var string */ protected $description = 'Allows you to be cool'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { echo "Yes you are very cool!"; } }

这是我的档案

func postRequestUsingDictionaryParametersImage(requestType : String, urlComponent : String, inputParameters : NSDictionary, completion: (result : NSData, httpResponse : NSHTTPURLResponse) -> Void, failure:(error: NSError) ->()){

    let accessToken : String = "Bearer " + (TNPAppData.sharedInstane.objTNPUserData?.accessToken)!
    let urlString: String = "\(kBaseURLString)\(urlComponent)"
    do {

        let jsonData = try NSJSONSerialization.dataWithJSONObject(inputParameters, options: NSJSONWritingOptions.PrettyPrinted)
        let jsonString = NSString(data: jsonData, encoding: NSUTF8StringEncoding)! as String
        let data = jsonString.dataUsingEncoding(NSASCIIStringEncoding, allowLossyConversion: false)


        let request = NSMutableURLRequest(URL: NSURL(string: urlString)!)
        request.HTTPMethod = requestType
        request.HTTPBody = data
        request.setValue("application/Json", forHTTPHeaderField: "Content-Type")
        request.setValue("multipart/form-data", forHTTPHeaderField: "Accept")
        request.setValue(accessToken, forHTTPHeaderField: "Authorization")


        let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
            guard error == nil && data != nil else {
                // check for fundamental networking error
                print("error=\(error)")
                failure(error: error!)
                return
            }

            do{
                let dict = try NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments) as! [String:AnyObject]
                print("Response from Server :", dict)

            }
            catch let error as NSError{
                print(error)
            }


            let httpStatus = response as? NSHTTPURLResponse

            print(httpStatus)

            if httpStatus?.statusCode ==  401 {

                // Make Request for New Access Token

                let str = TNPAppData.sharedInstane.objTNPUserData!.refreshToken

                let inputparameters = "grant_type=refresh_token&refresh_token=" + str

                print(inputparameters)

                self.requestTokenAgain2("token", inputParameters: inputparameters, requestType: "POST", refrshcompletion: { (result, httpResponse) in

                    do {

                        let dict = try NSJSONSerialization.JSONObjectWithData(result, options: .AllowFragments) as! [String:AnyObject]
                        print("Response from Server :", dict)

                        let httpStatus = httpResponse as? NSHTTPURLResponse

                        if httpStatus?.statusCode == 400{

                            completion(result: result, httpResponse: (response as? NSHTTPURLResponse)!)

                        }

                        else if httpStatus?.statusCode == 200{

                            let obj = TNPUserData(dictionary: dict)
                            TNPAppData.sharedInstane.objTNPUserData = obj

                            print("New Token Received")
                            print(obj.accessToken)
                            print(obj.bodyAccessToken)
                            print(obj.refreshToken)

                            // Now Call Get Details API Again
                            self.postRequestUsingDictionaryParameters2(requestType, urlComponent: urlComponent, inputParameters: inputParameters, completion: completion, failure: failure)
                        }
                        else{

                            // Go back to login screen

                            failure (error: error!)
                        }


                    } catch let error as NSError {
                        print(error)
                    }

                    }, failure: { (error) in

                        print(error)

                })

            } else {


                if error != nil {
                    failure (error: error!)
                } else {

                    completion(result: data!, httpResponse: (response as? NSHTTPURLResponse)!)
                }
            }


        }
        task.resume()
    }
    catch let error as NSError {
        print(error)
    }
}

当我点击php artisan时,命令未列在给定签名

我错过了什么? 感谢

1 个答案:

答案 0 :(得分:2)

如果在您键入php artisan时未列出,则您忘记按照here所述注册命令。打开app/Console/Kernel.php并输入您的命令。

 protected $commands = [
     Commands\CoolCommand::class
 ];