Laravel: Geocoder Error Call to a member function on null - laravel

General Information
I'm using this package
GeocoderLaravel Version: 4.0.0
Laravel Version: 5.6
PHP Version: 7.2.4
Operating System and Version: Windows 10
Issue Description
FatalThrowableError (E_ERROR)
Call to a member function getStreetNumber() on null
This happens maybe 1/10 times. Even when I use the same coordinates. Rest of the time it works fine. If I get the error and just refresh/resubmit the form it will work. So not sure how to solve this issue.
My one guess is that it is exicuting Location::create() before an object is returned to $geo, but I don't know what could be done to fix that. Any help would be much appreciated
Here is my controller:
$lat = request('lat');
$lng = request('lng');
$geo = Geocoder::reverse($lat, $lng)->get()->first();
$location = Location::create([
'lat' => $lat,
'lng' => $lng,
'user_id' => Auth::user()->id,
'streetNumber' => $geo->getStreetNumber(),
'streetName' => $geo->getStreetName(),
'cityDistrict' => $geo->getSubLocality(),
'city' => $geo->getLocality(),
'zipcode' => $geo->getPostalCode(),
'country' => $geo->getCountry(),
'timezone' => $geo->getTimezone()
]);

Related

Making an OAuth request with Laravel for Stripe

I was translating following PHP code:
$person = \Stripe\Account::createPerson(
'{{CONNECTED_ACCOUNT_ID}}', // id of the account created earlier
[
'person_token' => $token,
]);
To:
$making_user = $stripe->account()->persons()->create(
$request[0], // id of the account created earlier
[
'person_token' => $request[1],
]);
Above Laravel code works find without any issue. Does anyone have any idea that what can be the equivalent Laravel syntax of the following:
$response = \Stripe\OAuth::token([
'grant_type' => 'authorization_code',
'code' => 'ac_123456789',
]);
I'm using following as equivalent, but it is giving me error of invalid method "oauth"
$making_account = $stripe->oauth()->create([
'grant_type' => $request['code'],
'code' => 'ac_123456789',
]);
I'm not finding anywhere its syntax anyone have an idea what will be the Laravel syntax of making Oauth call?
This worked for me.
$stripe = new \Stripe\StripeClient('SECRET_KEY_HERE');
$response = $stripe->oauth->token([
'grant_type' => 'authorization_code',
'code' => 'CODE_HERE'
]);

Use of undefined constant INTL_IDNA_VARIANT_UTS46 error while doing payment on stripe, Laravel

I am getting this error while doing payment on stripe Laravel.
Use of undefined constant INTL_IDNA_VARIANT_UTS46 - assumed
'INTL_IDNA_VARIANT_UTS46'
My controller:
$stripe_secret = config('services.stripe.secret');
$stripe = Stripe::make($stripe_secret);
$charge = $stripe->charges()->create([
'currency' => 'USD',
'amount' => (float)$amount,
'source' => $payment_token,
'description' => '',
'receipt_email' => $receipt_email,
]);
This blog post describes the issue you're having. To fix the issue you should avoid guzzle 6.5.0.

Relations in resources?

So I'm planning to start using resources for my "API" (vue endpoint). So I started to search for some tutorials about the subject, and found a youtuber that describes the process. And I started making my own API resource. The youtuber shows briefly how to use the relations, but the thing is that I receive Property [description] does not exist on this collection instance. when trying to use the relation in the resource.
The current setup is:
$stack = Stack::select(['id', 'name', 'subject_id', 'description', 'image'])->where('id', '=', $requestId)->first();
$questions = $stack->load('question.choiceInRandomOrder');
return $questions;
And with resource it would be something like (notice choiceInRandomOrde, I would need that relation also):
return [
'subject' => $this->subject->name,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'image' => $this->image,
'questions' => [
'description' => $this->question->description,
'is_info' => $this->question->is_info,
'source' => $this->question->source,
'image' => $this->question->image,
]
];
}
And for testing, I have setup the following in my routes web.php
use App\Stack;
use App\Http\Resources\StackResource;
Route::get('/json', function(){
$stack = Stack::find(2);
return new StackResource($stack);
});
You try to access the name of subject in 'subject' => $this->subject->name, but you do not load the relation.
i don't know if i'm right but i thnk it has to be with the fact that ure not doing an Eloquent call but a Query Builder call (when doing $stack = Stack::select ... ). Why select just some fields in the call if you can choose the parameters to show directly in the model class? (see this).
Try to doing an Eloquent call instead (something like Stack::find(1)) and test it. It should work.

TaskQueue.php Error - Laravel 5 & Forge

When running any Posts and Model::create function within Laravel I am being greeted with the below error;
FatalErrorException in TaskQueue.php line 13:
Interface 'GuzzleHttp\Promise\TaskQueueInterface' not found
This was working perfectly fine on my local machine but as soon as the website was put onto a server with Forge it has started to show this error.
It looks like the server is trying to use the Queue function with Laravel but my code doesn't ever make use of this;
public function postCreateCustomer(){
$input = Request::all();
$customer = Customers::create([
'customer_name' => $input['customer_name'],
'customer_url' => $input['customer_url']
]);
$password = str_random(8);
$pass = Hash::make($password);
$user = User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => $pass,
'user_type' => 3,
'active_customer' => $customer->id,
]);
Access::create([
'user_id' => $user->id,
'customer_id' => $customer->id
]);
$the_content = '<p>Hello '.$input['name'].' ('.$input['customer_name'].'),</p>
<p>Thank you for creating an account. </p>
<p>Your login details are listed below;</p>
<p><strong>Username</strong>: '.$input['email'].'<p>
<p><strong>Password</strong>: '.$password.'<p>';
$contactEmail = $input['email'];
Mail::send('emails.default', ['the_content' => $the_content, 'the_heading' => 'Customer Account Created'], function ($message) use ($contactEmail) {
$message->subject("Customer Account Created");
$message->to($contactEmail);
});
Session::flash('success_message', 'The new customer has been created.');
return Redirect::to('/customers');
}
I faced the same problem and I found that was caused by the class "TaskQueueInterface" had not be found.
The following is my solution:
open the folder: /vendor/guzzlehttp/promises/src
edit TaskQueue.php
modify "class TaskQueue implements TaskQueueInterface" to "class TaskQueue"
After doing the above, stay tuned for the official release.

laravel 5 datatables collection not working

$data = array(
['name' => 'John Doe', 'email' => 'john#email.com'],
['name' => 'Robert Roe', 'email' => 'robert#email.com']
);
$users = new Collection($data);
return Datatables::of($users)->make();
I'm using the yajra/laravel-datatables plugin, it shows me that Collection functions are available on v5.x and later, but after i installed v5.11.10, and tried the above code, it gives me a Class 'Collection' not found error.
Should be a namespace issue. Make sure:
use Illuminate\Support\Collection;
is included at the top of your controller.

Resources