PHP Fatal error: Class 'Eloquent' not found - php

I have a script
<?php
require_once "vendor/autoload.php";
Dotenv::load(__DIR__);
use \App\VSE, \App\User;
// use Eloquent;
$accounts = VSE::account_all();
$accounts = json_decode (json_encode ($accounts), FALSE);
foreach ($accounts as $account) {
$user = new User;
$user->id = $account->account_id;
$user->account_id = $account->account_id;
$user->email = $account->email_address;
$user->auto_provisioning = null;
$user->service_plan = null;
$user->fb_email = '';
$user->tw_email = '';
$user->fb_access_token = '';
$user->fb_profile_id = '';
$user->fb_page_id = '';
$user->fb_username = '';
$user->save();
}
?>
I kept getting
PHP Fatal error: Class 'Eloquent' not found in /Applications/MAMP/htdocs/code/portal/app/User.php on line 6
How do I avoid that ?

It looks like the User model is using Eloquent.
Are you trying to use Eloquent in a standalone app? There is some setup required in order to do this... see example here:
https://github.com/illuminate/database
What is in your composer.json?

Related

Laravel 5.2 PaymayaSDK integration

I can't seem to include PaymayaSDK into my Laravel app I already run the command composer require "paymaya/paymaya-sdk:*" and it's already in the vendor folder. But when I try to use it in the controller it says Class 'PayMayaSDK' not found. I already try composer dump-autoload too.
This is my code
What am I missing?
I also tried integrating PaymayaSDK to Laravel via composer, it also didn't work for me.
What I did was I downloaded the PayMaya SDK from the github, then I put it in app\Libraries\PayMaya, but you have to change the namespace of the files of the sdk accordingly.
Also I think you have to edit the sample/Checkout/User.php also based on your requirements.
Here's my sample code:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Libraries\PayMaya\lib\PayMayaSDK;
use App\Libraries\PayMaya\lib\API\Webhook;
use App\Libraries\PayMaya\lib\API\Checkout;
use App\Libraries\PayMaya\lib\API\Customization;
use App\Libraries\PayMaya\lib\Model\Checkout\Item;
use App\Libraries\PayMaya\lib\Model\Checkout\ItemAmount;
use App\Libraries\PayMaya\sample\Checkout\User as PayMayaUser;
use App\Libraries\PayMaya\lib\Model\Checkout\ItemAmountDetails;
class PayMayaTestController extends Controller
{
public function setupPayMaya()
{
PayMayaSDK::getInstance()->initCheckout(
env('PAYMAYA_PUBLIC_KEY'),
env('PAYMAYA_SECRET_KEY'),
(\App::environment('production') ? 'PRODUCTION' : 'SANDBOX')
);
$this->setShopCustomization();
$this->setWebhooks();
return redirect('/');
}
public function redirectToPayMaya()
{
$sample_item_name = 'Product 1';
$sample_total_price = 1000.00;
$sample_user_phone = '1234567';
$sample_user_email = 'test#gmail.com';
$sample_reference_number = '1234567890';
PayMayaSDK::getInstance()->initCheckout(
env('PAYMAYA_PUBLIC_KEY'),
env('PAYMAYA_SECRET_KEY'),
(\App::environment('production') ? 'PRODUCTION' : 'SANDBOX')
);
// Item
$itemAmountDetails = new ItemAmountDetails();
$itemAmountDetails->tax = "0.00";
$itemAmountDetails->subtotal = number_format($sample_total_price, 2, '.', '');
$itemAmount = new ItemAmount();
$itemAmount->currency = "PHP";
$itemAmount->value = $itemAmountDetails->subtotal;
$itemAmount->details = $itemAmountDetails;
$item = new Item();
$item->name = $sample_item_name;
$item->amount = $itemAmount;
$item->totalAmount = $itemAmount;
// Checkout
$itemCheckout = new Checkout();
$user = new PayMayaUser();
$user->contact->phone = $sample_user_phone;
$user->contact->email = $sample_user_email;
$itemCheckout->buyer = $user->buyerInfo();
$itemCheckout->items = array($item);
$itemCheckout->totalAmount = $itemAmount;
$itemCheckout->requestReferenceNumber = $sample_reference_number;
$itemCheckout->redirectUrl = array(
"success" => url('returl-url/success'),
"failure" => url('returl-url/failure'),
"cancel" => url('returl-url/cancel'),
);
$itemCheckout->execute();
$itemCheckout->retrieve();
return redirect()->to($itemCheckout->url);
}
private function setShopCustomization()
{
$shopCustomization = new Customization();
$shopCustomization->get();
$shopCustomization->logoUrl = asset('logo.jpg');
$shopCustomization->iconUrl = asset('favicon.ico');
$shopCustomization->appleTouchIconUrl = asset('favicon.ico');
$shopCustomization->customTitle = 'PayMaya Payment Gateway';
$shopCustomization->colorScheme = '#f3dc2a';
$shopCustomization->set();
}
private function setWebhooks()
{
$webhooks = Webhook::retrieve();
foreach ($webhooks as $webhook) {
$webhook->delete();
}
$successWebhook = new Webhook();
$successWebhook->name = Webhook::CHECKOUT_SUCCESS;
$successWebhook->callbackUrl = url('callback/success');
$successWebhook->register();
$failureWebhook = new Webhook();
$failureWebhook->name = Webhook::CHECKOUT_FAILURE;
$failureWebhook->callbackUrl = url('callback/error');
$failureWebhook->register();
}
}
Seems you haven't configured properly.
Please read the usage section.
After installing you need to replace PayMaya-PHP-SDK with the vendor.

How to create a preAuthorized PayIn with the MangoPay PHP SDK?

I'm currently working on a project with the MangoPay api (with PHP SDK) and I have some trouble with the PaymentDetails. The function below generate this key (when I call the MangoPay Create method on my PayIn object) :
payins_stdclass-direct_create
instead of :
payins_preauthorized-direct_create
The function I'm using :
<?php
private function createAuthorizationPayIn($authorization, $fees)
{
$payIn = new MangoPay\PayIn();
$payIn->CreditedWalletId = $this->adminWalletId;
$payIn->AuthorId = $this->adminUserId;
$payIn->PaymentType = "PREAUTHORIZED";
$PayIn->PaymentDetails = new MangoPay\PayInPaymentDetailsPreAuthorized();
$payIn->PaymentDetails->PreauthorizationId = $authorization->Id;
$payIn->DebitedFunds = new MangoPay\Money();
$payIn->DebitedFunds->Currency = $authorization->DebitedFunds->Currency;
$payIn->DebitedFunds->Amount = $authorization->DebitedFunds->Amount;
$payIn->CreditedFunds = new MangoPay\Money();
$payIn->CreditedFunds->Currency = $authorization->DebitedFunds->Currency;
$payIn->CreditedFunds->Amount = $authorization->DebitedFunds->Amount;
$payIn->Fees = $fees;
$payIn->ExecutionType = "DIRECT";
$payIn->ExecutionDetails = new MangoPay\PayInExecutionDetailsDirect();
$payIn->ExecutionDetails->SecureMode = "DEFAULT";
$payIn->ExecutionDetails->SecureModeReturnURL = "https://website.com";
$payIn = $this->mangoPayApi->PayIns->Create($payIn);
$authorization->payinId = $payIn->Id;
$authorization = $this->mangoPayApi->CardPreAuthorizations->Update($authorization);
return $payIn;
}
How can I create the right PaymentDetails object to create a preAuthorized PayIn ?

ERROR: Object of class stdClass could not be converted to string

When I run the code below
$id = Input::get('branch_id');
$retailer_code = DB::table('branches')->select('retailer_code')->where('id', $id)->first();
$user = new User;
$user->user_firstname = Input::get('user_firstname');
$user->user_lastname = Input::get('user_lastname');
$user->user_email = Input::get('user_email');
$user->username = Input::get('username');
$user->password = Hash::make(Input::get('password'));
$user->position_id = Input::get('position_id');
$user->retailer_code = $retailer_code;
$user->branch = Input::get('branch_code');
$user->status = "1";
$user->save();
return Redirect::to('admin/users')->with('message', 'New User Added!');
I get this error "Object of class stdClass could not be converted to string"
$retailer_code which is stdClass and you cannot use directly as variable ,
$retailer_code = DB::table('branches')->select('retailer_code')->where('id', $id)->first();
will returns the retailer_code so
$retailer_code->retailer_code //would be the solution.
Please refer this link.
The problem is probably on this line:
$user->retailer_code = $retailer_code;
$retailer_code is an object and you need to get the property of it like this:
$user->retailer_code = $retailer_code->retailer_code;
You should change:
$user->retailer_code = $retailer_code;
into
$user->retailer_code = $retailer_code->retailer_code;
or you could modify your query:
$retailer_code = DB::table('branches')->where('id', $id)->pluck('retailer_code');
and then use:
$user->retailer_code = $retailer_code;
without a change

Switching databases in code igniter

I have two databases I need to connect to, which I can do in the controllers and libraries I have written. For some odd reason (i'm assuming I'm just missing something simple here) I can't get it to work in the model all of the sudden. I have read the database class in the CI user guide.
I tried making a reference to $pew when loading pew ($this->pew =& $this->load->database('pew', TRUE)) to no avail.
Any thoughts, suggestions? Thanks!
Error
PHP Fatal error: Call to a member function query() on a non-object in
/Sites/CI/nyan/application/models/pewpewmodel.php on line 15
Line 15
$this->pew->query('SELECT * FROM ExtractEvent'); //simplified for testing
database.php:
$active_group = 'nyan';
$active_record = TRUE;
$db['nyan']['hostname'] = 'catcatcat';
$db['nyan']['username'] = 'mew';
$db['nyan']['password'] = 'meow';
$db['nyan']['database'] = 'meow';
$db['nyan']['dbdriver'] = 'mysql';
$db['pew']['hostname'] = 'jujubees';
$db['pew']['username'] = 'qwop';
$db['pew']['password'] = 'qwop';
$db['pew']['database'] = 'nom';
$db['pew']['dbdriver'] = 'mssql';
Model pewpewmodel.php
private $pew;
function __construct()
{
parent::__construct();
$this->pew = $this->load->database('pew', TRUE);
}
function get_forms_by_date($id = NULL, $Year = NULL, $Month = NULL, $Day = NULL)
{
$this->pew->query('SELECT * FROM ExtractEvent'); //simplified for testing
}
Controller nomnom.php
public function index()
{
$this->load->model('pewmodel');
$data['Forms'] = $this->pewmodel->get_forms_by_date($this->session->userdata('Username'), date('Y'), date('n'), date('j'));
$this->load->view('common/header', $data['Forms']);
$this->load->view('home/index');
$this->load->view('common/footer');
}
View index.php
<pre>
<?php print_r($Forms); ?>
</pre>
This worked for me.
[from within the model constructor]
$db['hostname'] = 'localhost';
$db['username'] = 'root';
$db['password'] = '';
$db['database'] = 'my_database';
$db['dbdriver'] = 'mysql';
$db['dbprefix'] = '';
$db['pconnect'] = TRUE;
$db['db_debug'] = TRUE;
$db['cache_on'] = FALSE;
$db['cachedir'] = '';
$db['char_set'] = 'latin1';
$db['dbcollat'] = 'latin1_bin';
$db['swap_pre'] = '';
$db['autoinit'] = TRUE;
$db['stricton'] = FALSE;
$this->load->database($db, FALSE, TRUE);
// False=don't return db object
// True =use as active record, so it replaces default $this->db
Hope this helps coders searching through Google like I did.
$this->pew = $this->load->database('pew', TRUE);
You load a database which doesn't exist in your database-configuration.
I was getting a 500 error when I passed TRUE to connect like below. I assumed (yeah I know) that I was just having the same problem with connecting. truth be told it was an ID10T error from the beginning. I was missing the mssql.so library on my local machine and another I was testing from.
$this->pew =& $this->load->database('pew', TRUE)
My apologies for the waste of time gents.

PHP classes are keeping me from accessing the needed variable

ok so i have a php file that includes code for do a sql insert
myfile.php
include($somewhere.'/addleads.php');
addleads.php
require_once(MAIN_CLASS_PATH."common/class.Common.php");
require_once(MAIN_CLASS_PATH."modules/Leads/class.Leads.php");
$objcommon = new common();
$objLeads = new Leads();
$Errormsg = $objLeads->AddLBCleads($_REQUEST);
class.Leads.php
class Leads extends Common{
function Leads(){
$this->Common();
$this->Leadstype = "Leadstype";
$this->Leads = "Leads";
}
function AddLBCleads($objArray){
global $_REQUEST,$objSmarty,$global_config;
$objLeads = new Leads();
$objInsertArray['txtP_Ident'] = $objArray['selProperty'];
$objInsertArray['txtFirstName'] = $objArray['txtfirstname'];
$objInsertArray['txtLastName'] = $objArray['txtlastname'];
$objInsertArray['txtEmail'] = $objArray['txtEmail'];
$objInsertArray['txtPhone'] = $objArray['txtPhone'];
$objInsertArray['txtTypeId'] = $objArray['selleadtype'];
$objInsertArray['txtComments'] = $objArray['txtcomments'];
$StrEnterdate = date('Y-m-d H:i:s');
$objInsertArray['txtMoveDate'] = $StrMoveDate;
$objInsertArray['txtEntereddate'] = $StrEnterdate;
$current_id = $this->AddInfoToDB($objInsertArray,"txt",$this->LBCPrimary_leads);
How do i get $current_id from myfile.php, when i try to access it is unavailable
Just below this line:
class Leads extends Common{
Add:
public $current_id = null; // create a public accessible variable
And instead of:
$current_id = $this->AddInfoToDB($objInsertArray,"txt",$this->LBCPrimary_leads);
Use:
$this->current_id = $this->AddInfoToDB($objInsertArray,"txt",$this->LBCPrimary_leads);
Now you can get it like:
$objLeads = new Leads();
echo $objLeads->current_id;

Categories