Call to undefined method Illuminate\Database\Query\Builder::save()- Laravel 5 - php

I can't figure it out. I think it happens when it hits my activateAccount controller function. Inside that function I call on account_activated function where user gets saved. Plus I'm getting the first instance of the user object so I don't what's wrong.
This is the controller function
public function activateAccount(Request $request, User $user, $key) {
$registered = $request->session()->get('registered');
if (isset($registered)) {
$request->session()->forget('registered');
if ($user->account_activated($key)) {
// TODO
$referral = Referrals::where('activation_key', $key);
if (!empty($referral)) {
$referral->validate = 1;
$referral->save();
}
return redirect('/login')->with('success', "Your account has been activated. You many login!");
} else {
return redirect('/not-active');
}
} else {
return redirect('/');
}
}
account_activated function inside the User model
public function account_activated($key){
$user = User::where('activate_key', $key)->first();
$user->activate = 1;
$user->save();
return true;
}
This is the error msg
BadMethodCallException in Builder.php line 2047:
Call to undefined method Illuminate\Database\Query\Builder::save()
in Builder.php line 2047
at Builder->__call('save', array())
at Builder->save()
at call_user_func_array(array(object(Builder), 'save'), array()) in Builder.php line 943
at Builder->__call('save', array()) in RegisterController.php line 155
at Builder->save() in RegisterController.php line 155
at RegisterController->activateAccount(object(Request), object(User), 'OjkTKaLIVAaRhveYRZz9rC1uAuPjUc6fk4BeZhUM')
at call_user_func_array(array(object(RegisterController), 'activateAccount'), array(object(Request), object(User), 'key' => 'OjkTKaLIVAaRhveYRZz9rC1uAuPjUc6fk4BeZhUM')) in Controller.php line 256
at Controller->callAction('activateAccount', array(object(Request), object(User), 'key' => 'OjkTKaLIVAaRhveYRZz9rC1uAuPjUc6fk4BeZhUM')) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(RegisterController), object(Route), 'activateAccount') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{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 114
at ControllerDispatcher->callWithinStack(object(RegisterController), object(Route), object(Request), 'activateAccount') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\RegisterController', 'activateAccount') in Route.php line 201
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{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 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
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 124
at Pipeline->Illuminate\Pipeline\{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 124
at Pipeline->Illuminate\Pipeline\{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 124
at Pipeline->Illuminate\Pipeline\{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 124
at Pipeline->Illuminate\Pipeline\{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 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
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 124
at Pipeline->Illuminate\Pipeline\{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 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

The error that you are getting isn't coming from the function that you call, but within the activateAccount function itself.
In particular these lines here:
$referral = Referrals::where('activation_key', $key);
if (!empty($referral)) {
$referral->validate = 1;
$referral->save();
}
You need to fetch the model after giving your where clause. By the looks of it you already know how to do this, but for completeness sake you just need to add in a ->first():
$referral = Referrals::where('activation_key', $key)->first();
if (!empty($referral)) {
$referral->validate = 1;
$referral->save();
}

Related

Laravel 5.2 appear weird : Method [validateNickName] does not exist

Version:Laravel 5.2
issue:
BadMethodCallException in Validator.php line 3295:
Method [validateNickName] does not exist.
in Validator.php line 3295
at Validator->__call('validateNickName', array('nick_name', 'chenmin', array(), object(Validator))) in Validator.php line 485
at Validator->validateNickName('nick_name', 'chenmin', array(), object(Validator)) in Validator.php line 485
at Validator->validate('nick_name', 'nick_name') in Validator.php line 425
at Validator->passes() in Validator.php line 450
at Validator->fails() in ValidatesRequests.php line 53
at Controller->validate(object(Request), array('nick_name' => 'required|nick_name|unique:users|max:30', 'cellphone' => 'required|cellphone|unique:users|numeric|phone_number|size:11', 'captcha' => 'required|numeric|size:6', 'password' => 'required|min:6|max:30')) in UserController.php line 19
at UserController->postSignUp(object(Request))
at call_user_func_array(array(object(UserController), 'postSignUp'), array(object(Request))) in Controller.php line 80
at Controller->callAction('postSignUp', array(object(Request))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(UserController), object(Route), 'postSignUp') 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(UserController), object(Route), object(Request), 'postSignUp') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\UserController', 'postSignUp') 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
source code:
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function postSignUp(Request $request)
{
$this->validate($request, [
'nick_name' => 'required|nick_name|unique:users|max:30',
'cellphone' => 'required|cellphone|unique:users|numeric|phone_number|size:11',
'captcha' => 'required|numeric|size:6',
'password' => 'required|min:6|max:30'
]);
.......
when I test the input from ,met a weird issue:BadMethodCallException in Validator.php line 3295:Method [validateNickName] does not exist.
who can help me to solve it ?thanks a lot!
nickn_name and cell_phone and phone_number are not validation rules?
so you cannot put them in the rule string. Your validation rules should looks as follow:
$this->validate($request, [
'nick_name' => 'required|unique:users|max:30',
'cellphone' => 'required|unique:users|numeric|size:11',
'captcha' => 'required|numeric|size:6',
'password' => 'required|min:6|max:30'
]);
I think is because you are using snake_case for nick_name, and somehow the validator thinks that you are calling a custom validation rule called nickName (bits of Laravel always convert snake_case to camelCase when helpers are called)... why would you call nickname nick_name ? In english I think is just one word...

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.

How to gracefully show an error screen when the session has expired in Laravel 5?

I have set the config/session.php to kill the session in half an hour. However, when I want to check if the session has expired (which it has), the following error screen pops up, when e.g. I click on my Holidays link:
in HolidayController.php line 46
at HandleExceptions->handleError('8', 'Trying to get property of non-object', 'C:\xampp\htdocs\empirehrms\app\Http\Controllers\HolidayController.php', '46', array('user' => null)) in HolidayController.php line 46
at HolidayController->create()
at call_user_func_array(array(object(HolidayController), 'create'), array()) in Controller.php line 80
at Controller->callAction('create', array()) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(HolidayController), object(Route), 'create') 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(HolidayController), object(Route), object(Request), 'create') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\HolidayController', 'create') 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
I would like to show the user a page that tells them that they need to log in again.

Laravel 5.2 and PayPayl integration for payments?

I'm a newbie on Laravel, and I'm trying to implement PayPal on my website.
Already tried searching PayPal packages on GitHub, but most of them are outdated, or without enough documentantion.
So I'm here to ask if someone has an idea to integrate PayPal payments (express checkout) on Laravel 5.2 ?
So I took this package; http://packalyst.com/packages/package/netshell/paypal
And just did what the doc says, the composer require netshell/paypal dev-master, then add the service provider and alias on the app.php.
I tried the "ExampleController" given, by making a new controller called "PaymentController", and added a few lines on my routes.php.
Here is my PaymentController;
'namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Gloudemans\Shoppingcart\Facades\Cart;
use PayPal;
use Redirect;
use App\Http\Requests;
class PaymentController extends Controller
{
private $_apiContext;
public function __construct()
{
$this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret'));
$this->_apiContext->setConfig(array(
'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
));
}
public function getCheckout()
{
$payer = PayPal::Payer();
$payer->setPaymentMethod('paypal');
$amount = PayPal:: Amount();
$amount->setCurrency('EUR');
$amount->setTotal(42); // This is the simple way,
// you can alternatively describe everything in the order separately;
// Reference the PayPal PHP REST SDK for details.
$transaction = PayPal::Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('What are you selling?');
$redirectUrls = PayPal:: RedirectUrls();
$redirectUrls->setReturnUrl(action('PaymentController#getDone'));
$redirectUrls->setCancelUrl(action('PaymentController#getCancel'));
$payment = PayPal::Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
$response = $payment->create($this->_apiContext);
$redirectUrl = $response->links[1]->href;
return Redirect::to( $redirectUrl );
}
public function getDone(Request $request)
{
$id = $request->get('paymentId');
$token = $request->get('token');
$payer_id = $request->get('PayerID');
$payment = PayPal::getById($id, $this->_apiContext);
$paymentExecution = PayPal::PaymentExecution();
$paymentExecution->setPayerId($payer_id);
$executePayment = $payment->execute($paymentExecution, $this->_apiContext);
// Clear the shopping cart, write to database, send notifications, etc.
// Thank the user for the purchase
return view('checkout.done');
}
public function getCancel()
{
// Curse and humiliate the user for cancelling this most sacred payment (yours)
return view('checkout.cancel');
}'
And my routes.php
`Route::group(['prefix' => 'payment'], function () {
Route::get('/', 'PaymentController#getCheckout');
});`
And I got this error
`InvalidArgumentException in UrlGenerator.php line 603:
Action App\Http\Controllers\PaymentController#getDone not defined.
in UrlGenerator.php line 603
at UrlGenerator->action('PaymentController#getDone', array(), true) in helpers.php line 87
at action('PaymentController#getDone') in PaymentController.php line 48
at PaymentController->getCheckout()
at call_user_func_array(array(object(PaymentController), 'getCheckout'), array()) in Controller.php line 78
at Controller->callAction('getCheckout', array()) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(PaymentController), object(Route), 'getCheckout') 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(PaymentController), object(Route), object(Request), 'getCheckout') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\PaymentController', 'getCheckout') 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 124
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 124
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 124
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 124
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 124
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 124
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`

laravel 5: sending email does not work

I'm new to laravel and am currently stuck when trying to send an email like this:
Mail::send('emails.pwreset', $mydata, function ($message) use ($mydata) {
$message->from('foo#bar.de', 'Password reset');
how can I enable/configure the mailing function?
here's my laravel error message:
Swift_TransportException in StreamBuffer.php line 294: Process could not be started [Das System kann den angegebenen Pfad nicht finden.
]
in StreamBuffer.php line 294
at Swift_Transport_StreamBuffer->_establishProcessConnection() in StreamBuffer.php line 58
at Swift_Transport_StreamBuffer->initialize(array('timeout' => '30', 'blocking' => '1', 'command' => '/usr/sbin/sendmail -bs', 'type' => '16')) in AbstractSmtpTransport.php line 113
at Swift_Transport_AbstractSmtpTransport->start() in SendmailTransport.php line 51
at Swift_Transport_SendmailTransport->start() in Mailer.php line 79
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 398
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 188
at Mailer->send('emails.pwreset', array('passwort' => 'WVSSV', 'empf' => 'foo#bar.de'), object(Closure)) in Facade.php line 216
at Facade::__callStatic('send', array('emails.pwreset', array('passwort' => 'WVSSV', 'empf' => 'foo#bar.de'), object(Closure))) in ResetpwController.php line 58
at Mail::send('emails.pwreset', array('passwort' => 'WVSSV', 'empf' => 'foo#bar.de'), object(Closure)) in ResetpwController.php line 58
at ResetpwController->resetted(object(Request))
at call_user_func_array(array(object(ResetpwController), 'resetted'), array(object(Request))) in Controller.php line 256
at Controller->callAction('resetted', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(ResetpwController), object(Route), 'resetted') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{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 114
at ControllerDispatcher->callWithinStack(object(ResetpwController), object(Route), object(Request), 'resetted') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Resetpw\ResetpwController', 'resetted') in Route.php line 201
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{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 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 54
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 124
at Pipeline->Illuminate\Pipeline\{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 124
at Pipeline->Illuminate\Pipeline\{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 124
at Pipeline->Illuminate\Pipeline\{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 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
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 124
at Pipeline->Illuminate\Pipeline\{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 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
It looks like /usr/sbin/sendmail does not exist. Is sendmail installed and properly configured?
Also check the Swift Mailer settings inside your application.

Categories