Laravel unique validation class Class Dokter does not exist - php

i have some problem with unique validation laravel
<?php
namespace Amodules\Hmastermedis\Http\Controllers;
use Illuminate\Http\Request;
use Amodules\Hmastermedis\Models\Dokter;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Theme;
use Amodules\Hmastermedis\Models\Spesialisasi;
use Yajra\Datatables\Facades\Datatables;
use DB;
use Session;
use validate;
class DokterController extends Controller
{
public function store(Request $request)
{
$this->validate($request, [
'dr_cd' => 'required|unique:Dokter',
'dr_nm' => 'required',
]);
$dokter = new Dokter();
$dokter->dr_cd=$request->dr_cd;
$dokter->dr_nm=$request->dr_nm;
$dokter->spesialis_cd=$request->spesialis_cd;
$dokter->save();
Session::flash('dokter', 'Dokter berhasil di tambahkan');
return redirect('hmastermedis/dokter');
}
}
and this my model
<?php
namespace Amodules\Hmastermedis\Models;
use Illuminate\Database\Eloquent\Model;
/**
*
*/
class Dokter extends Model
{
public $primarykey = 'dr_cd';
public $incrementing = false;
protected $fillable = ['dr_cd','dr_cm','spesialis_cd','paramedis_tp'];
protected $table = 'trx_dokter';
public $timestamps = false;
public function spesialisasi()
{
return $this->hasOne('Amodules\Hmastermedis\Models\Spesialisasi','spesialis_cd','spesialis_cd');
}
}
but when i run my code, class dokter does not exist
Whoops, looks like something went wrong.
1/1 ReflectionException in IlluminateRegistry.php line 334: Class Dokter does not exist
in IlluminateRegistry.php line 334
at ReflectionClass->__construct('Dokter') in IlluminateRegistry.php line 334
at IlluminateRegistry->getManagerForClass('Dokter') in DoctrinePresenceVerifier.php line 123
at DoctrinePresenceVerifier->getEntityManager('Dokter') in DoctrinePresenceVerifier.php line 92
at DoctrinePresenceVerifier->select('Dokter') in DoctrinePresenceVerifier.php line 45
at DoctrinePresenceVerifier->getCount('Dokter', 'dr_cd', 'df', null, null, array()) in Validator.php line 1426
at Validator->validateUnique('dr_cd', 'df', array('Dokter'), object(Validator)) in Validator.php line 545
at Validator->validateAttribute('dr_cd', 'unique:Dokter') in Validator.php line 461
at Validator->passes() in Validator.php line 486
at Validator->fails() in ValidatesRequests.php line 54
at Controller->validate(object(Request), array('dr_cd' => 'required|unique:Dokter', 'dr_nm' => 'required')) in DokterController.php line 60
at DokterController->store(object(Request))
at call_user_func_array(array(object(DokterController), 'store'), array(object(Request))) in Controller.php line 55
at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(DokterController), 'store') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
at require_once('D:\xampp\htdocs\amteklab\AMHES\public\index.php') in server.php line 21
thanks four your help

If your model class was created after the controller you are calling it from you need to run composer dump-autoload so that the Dokter is added to the project's autoload_classmap.php

Related

Trying to get property of non-object laravel bogardo/mailgun/src/http/response

This error appears when I try to send email with mailgun package for laravel (bogardo/mailgun).
Route:
Route::post('mail-list/send/{type}/{id}', ['uses' => 'MailingList\MailingListController#sendSiteNews', 'as' => 'mail-list.send']);
Controller MailingListController
use Bogardo\Mailgun\Mail\Message;
use Mailgun;
Controller method:
public function sendSiteNews($type, $id) {
$data = [];
Mailgun::send('email.batch-news', $data, function (Message $message) {
$message->to('foo#example.com', 'John Smith')->subject('Welcome!');
});
];
At first I've tried batch sending. Result was the same. After that I've tried to send simple message like above.
view email.batch-news contains only text with h1 tag.
Error message:
ErrorException in Response.php line 35:
Trying to get property of non-object
in Response.php line 35
at HandleExceptions->handleError(8, 'Trying to get property of non-object', 'D:\\wamp\\www\\asiacrochet\\vendor\\bogardo\\mailgun\\src\\Http\\Response.php', 35, array('response' => object(stdClass))) in Response.php line 35
at Response->__construct(object(stdClass)) in Mailer.php line 68
at Mailer->send('email.batch-news', array(), object(Closure)) in Service.php line 59
at Service->send('email.batch-news', array(), object(Closure)) in Facade.php line 221
at Facade::__callStatic('send', array('email.batch-news', array(), object(Closure))) in MailingListController.php line 67
at MailingListController->sendSiteNews('Lesson', '10')
at call_user_func_array(array(object(MailingListController), 'sendSiteNews'), array('Lesson', '10')) in Controller.php line 55
at Controller->callAction('sendSiteNews', array('Lesson', '10')) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(MailingListController), 'sendSiteNews') in Route.php line 203
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in HasRole.php line 24
at HasRole->handle(object(Request), object(Closure), 'administrator') in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 43
at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 561
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 520
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 47
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 53
That is method of package:
public function __construct(stdClass $response)
{dd($response->http_response_body);
$this->status = $response->http_response_code;
$this->message = $response->http_response_body->message;
$this->id = property_exists($response->http_response_body, 'id') ? $response->http_response_body->id : '';
$this->data = null;
}
dd($response->http_response_body);
gives only that string value "Mailgun Magnificent API".
So that is the problem.
Check your send-domain "email.batch-news". If this is incorrect mailgun, does identify the API method you are calling.

Redirect with parameters laravel 5.3 | InvalidArgumentException in Response.php line 462

Hi I'm new to laravel and got stuck.
in my app there are three types of users. their login data is kept in a single table(users table generated with auth), with a char to define the user type. What I want to do is when they log in, redirect them to relevant page with their user_id (obtained from the users table) on the url.
bottomline is I want to get the url as
localhost:8000/ESProfile/15
where value 15 is the user_id of the table.
What I've done so far is below.
In AuthenticatesUsers.php (auto generated from artisan auth)
protected function authenticated(Request $request, $user)
{
$userId = $user->id;
if($user->type === 's') {
return redirect('ESProfile', $userId);
}
else if($user->type === 'p') {
return redirect('/ePProfile');
}
else if($user->type === 'i') {
return redirect('/ePDashboard');
}
}
In web.php
Route::get('ESProfile/{id}', function($id){ return view('ESeeker.details')->with('$id'); });
when I try to login, it gives
InvalidArgumentException in UrlGenerator.php line 314: Route [ESProfile] not defined. error.
along with
in UrlGenerator.php line 314
at UrlGenerator->route('ESProfile', array('15'), true) in helpers.php line 692
at route('ESProfile', array('15')) in AuthenticatesUsers.php line 123
at LoginController->authenticated(object(Request), object(User)) in AuthenticatesUsers.php line 107
at LoginController->sendLoginResponse(object(Request)) in AuthenticatesUsers.php line 46
at LoginController->login(object(Request))
at call_user_func_array(array(object(LoginController), 'login'), array(object(Request))) in Controller.php line 55
at Controller->callAction('login', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(LoginController), 'login') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in RedirectIfAuthenticated.php line 24
at RedirectIfAuthenticated->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\xampp\htdocs\Project\public\index.php') in server.php line 21
Thanks in advance.
In your view, you must be using following code
route('ESProfile', ['id' => $id])
which will obviously fail because you have not defined ESProfile anywhere.
Change your route to following to wrok:
Route::get('ESProfile/{id}', function($id) {
return view('ESeeker.details')->with('$id');
})->name('ESProfile');
Check docs for named routes.
After many trials found my answer.
In RegistersUsers.php (auto generated file from php artisan make:auth)
public function register(Request $request){
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
$user = $request -> user();
if(($user->type) == 's'){
return $this->registered($request, $user)?: redirect()-> intended('/addPreferences/ESId='.$user->id);
}
if(($user->type) == 'p'){
return $this->registered($request, $user)?: redirect()-> intended('/ePProfile/epID='.$user->id);
}
}
appending desired path with intended method did the trick. Thanks.
(special thanks goes to iCode)

Class not found in job with protected variable

I'm trying to create a Job, but when i set the line:
protected $param;
to pass the data from __construct to handle() I start getting this error:
Class not found
When I removed the protected $param; line, the Job works perfectly. But I'm not able to get the data. What can I do to fix this?
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Repositories\ProductRepository;
class ImportProducts extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $param;
/**
* Create a new job instance.
*
* #return void
*/
public function __construct($param)
{
$this->param = $param;
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
//$products = $this->param['products'];
exit();
}
}
This is the entire error message:
Whoops, looks like something went wrong.
1/1
ReflectionException in Container.php line 734:
Class does not exist
in Container.php line 734
at ReflectionClass->__construct('') in Container.php line 734
at Container->build('', array()) in Container.php line 629
at Container->make('', array()) in Application.php line 697
at Application->make('') in Job.php line 154
at Job->resolve('') in Job.php line 210
at Job->failed() in SyncQueue.php line 153
at SyncQueue->handleFailedJob(object(SyncJob)) in SyncQueue.php line 36
at SyncQueue->push(object(ImportProducts), '', 'upload_products_file') in Queue.php line 40
at Queue->pushOn('upload_products_file', object(ImportProducts)) in Dispatcher.php line 135
at Dispatcher->pushCommandToQueue(object(SyncQueue), object(ImportProducts)) in Dispatcher.php line 117
at Dispatcher->dispatchToQueue(object(ImportProducts)) in Dispatcher.php line 66
at Dispatcher->dispatch(object(ImportProducts)) in DispatchesJobs.php line 17
at Controller->dispatch(object(ImportProducts)) in ProductController.php line 656
at ProductController->importProducts(object(Request))
at call_user_func_array(array(object(ProductController), 'importProducts'), array(object(Request))) in Controller.php line 80
at Controller->callAction('importProducts', array(object(Request))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(ProductController), object(Route), 'importProducts') 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(ProductController), object(Route), object(Request), 'importProducts') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\ProductController', 'importProducts') 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 VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), '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 64
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
When a job use SerializesModels trait expect a Eloquent model in the constructor.
You gave something different from an Eloquent Model in the constructor and Laravel, because the trait SerializesModels is trying to reconstruct the Eloquent object from the class of $param, but it cannot find it.
Try to remove SerializesModels from the traits of the job.

Request validation error on production, not on local

So i've search the farthest reaches of the internet and come up with nothing. Please help!
I am developing locally on my Mac, all is fine.
When I push the site to production (CentOS7 VPS) I get the following error:
BadMethodCallException in Validator.php line 3162:
Method [validatePublication] does not exist.
Here is my 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;
}
}
```
Here is my 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()
{
//
}
}
```
Here is my 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',
];
}
}
```
This is the request that is failing on production. Again, I stress this is not a problem on my local Mac.
Any thoughts? I'm stumped...
Thanks!
UPDATE: Stack trace...
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
Turns out it was a filename in app.php when registering the service provider.
I missed it as on local, the filename was correct. However I have a merge-driver setup that I completely forgot about preventing app.php being merged with staging (because of the application URL), so the error persisted.
I think I need to move the application URL to an environment variable and load the relevant config, getting rid of the merge driver.
Thanks to the guys at Laracasts for helping me get to the bottom of this..
https://laracasts.com/discuss/channels/laravel/error-on-production-not-on-local

Laravel 5 Routing Issue - Bad Method Call Exception

I'm attempting to simply send a 'PUT' request to one of my routes (which is called as a resource in the route file), yet I recieve this traceback as the response.
Whoops, looks like something went wrong.
1/1 BadMethodCallException in Controller.php line 273: Method [show] does not exist.
in Controller.php line 273
at Controller->__call('show', array('1'))
at AccountControllerV2->show('1')
at call_user_func_array(array(object(AccountControllerV2), 'show'), array('account' => '1')) in Controller.php line 246
at Controller->callAction('show', array('account' => '1')) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(AccountControllerV2), object(Route), 'show') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(AccountControllerV2), object(Route), object(Request), 'show') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\API\V2\AccountControllerV2', 'show') in Route.php line 198
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
at Route->run(object(Request)) in Router.php line 692
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Authenticate.php line 47
at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 694
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 661
at Router->dispatchToRoute(object(Request)) in Router.php line 619
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in HttpsProtocol.php line 15
at HttpsProtocol->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
I cannot for the life of me figure out why this is happening.
Here is a code snippet from the Controller itself (which extends BaseController):
/**
* Update the currently logged User in storage.
*
* #return Response 201
* #return jsonArray account
* #return string message
*/
public function update($account_id) {
$input = Input::all();
$message = 'Account Successfully Updated';
$user = Auth::User();
And here is the Route declaration:
Route::group(array('prefix' => 'api/v2', 'namespace' => 'API\V2', 'middleware' => 'auth'), function()
{
Route::resource('challenges', 'ChallengeControllerV2', ['only'=> ['index','store','update','destroy']]);
Route::resource('groups', 'GroupControllerV2');
Route::resource('account', 'AccountControllerV2');
The call is being made to the correct path. Any ideas why I'm getting what seems to be an illogical response? There is no additional middleware/filters attached to the controller than what is shown.
It turns out that in Laravel 5 if you do not specify the resources available on a Route it will assume that they are all there (unlike in Laravel 4 where it checks to see what resources are available in all controllers). So I had to change the line like so.
Route::resource('account', 'AccountControllerV2', ['only'=> ['index','update','destroy']]);

Categories