所以我搜索了互联网最远的地方,什么都没有。请帮忙!
我在Mac上本地开发,一切都很好。
当我将网站推向生产(CentOS7 VPS)时,我收到以下错误:
Validator.php第3162行中的BadMethodCallException: 方法[validatePublication]不存在。
这是我的app / Services / Validation / CustomValidation.php
```
use Illuminate\Validation\Validator;
class CustomValidation extends Validator {
//added only for test
public function validateCartRow($attribute, $value, $parameters)
{
$valid = (is_null(\Cart::get($value))) ? false : true;
return $valid;
}
public function validatePublication($attribute, $value, $parameters)
{
$valid = (\PublisherAPI::publicationByID($value) == false) ? false : true;
return $valid;
}
}
```
这是我的app / Providers / ValidationServiceProvider.php
```
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Services\Validation\CustomValidation;
use Illuminate\Validation\Validator;
class ValidationServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->app->validator->resolver(function($translator, $data, $rules, $messages)
{
return new \App\Services\Validation\CustomValidation($translator, $data, $rules, $messages);
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
```
这是我的app / Http / Requests / Cart / addToCartRequest.php
```
namespace App\Http\Requests\Cart;
use App\Http\Requests\Request;
class addToCartRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'row_publication_id' => 'required|string|numeric|publication',
'row_price_key' => 'required|string|numeric',
];
}
}
```
这是生产失败的请求。我再次强调,这不是我本地Mac上的问题。
有什么想法?我很难过......
谢谢!
更新:堆栈跟踪......
in Validator.php line 3265
at Validator->__call('validatePublication', array('row_publication_id', '4', array(), object(Validator))) in Validator.php line 485
at Validator->validatePublication('row_publication_id', '4', array(), object(Validator)) in Validator.php line 485
at Validator->validate('row_publication_id', 'publication') in Validator.php line 425
at Validator->passes() in ValidatesWhenResolvedTrait.php line 24
at FormRequest->validate() in FoundationServiceProvider.php line 41
at FoundationServiceProvider->Illuminate\Foundation\Providers\{closure}(object(addToCartRequest), object(Application)) in Container.php line 1031
at Container->fireCallbackArray(object(addToCartRequest), array(object(Closure))) in Container.php line 996
at Container->fireResolvingCallbacks('App\Http\Requests\Cart\addToCartRequest', object(addToCartRequest)) in Container.php line 648
at Container->make('App\Http\Requests\Cart\addToCartRequest', array()) in Application.php line 697
at Application->make('App\Http\Requests\Cart\addToCartRequest') in RouteDependencyResolverTrait.php line 85
at ControllerDispatcher->transformDependency(object(ReflectionParameter), array(), array()) in RouteDependencyResolverTrait.php line 59
at ControllerDispatcher->resolveMethodDependencies(array(), object(ReflectionMethod)) in RouteDependencyResolverTrait.php line 42
at ControllerDispatcher->resolveClassMethodDependencies(array(), object(CartController), 'addToCart') in ControllerDispatcher.php line 144
at ControllerDispatcher->call(object(CartController), object(Route), 'addToCart') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(CartController), object(Route), object(Request), 'addToCart') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Cart\CartController', 'addToCart') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SessionTimeout.php line 58
at SessionTimeout->handle(object(Request), object(Closure))
at call_user_func_array(array(object(SessionTimeout), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54
答案 0 :(得分:0)
在注册服务提供商时,原来这是app.php中的文件名。
我在本地错过了它,文件名是正确的。但是我有一个合并驱动程序设置,我完全忘记了阻止app.php与登台合并(因为应用程序URL),所以错误仍然存在。
我想我需要将应用程序URL移动到环境变量并加载相关配置,摆脱合并驱动程序。
感谢Laracasts的工作人员帮助我深入了解这个......
https://laracasts.com/discuss/channels/laravel/error-on-production-not-on-local