Answer the question
In order to leave comments, you need to log in
Cashier ERROR: Method newSubscription() does not exist?
Here is my model:
namespace App\Entities;
use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Cashier\Billable;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Model implements Transformable
{
use TransformableTrait, Notifiable, Billable, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
'account_type',
'stripe_id',
'card_brand',
'card_last_four',
'trial_ends_at',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'remember_token',
];
protected $dates = [
'trial_ends_at',
'ends_at',
];
}
namespace App\Http\Controllers\Auth;
use App\Entities\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
....
protected function create(array $data)
{
$stripeToken = $data['stripeToken'];
$accountType = strtolower($data['account_type']);
$user = User::create([
'account_type' => $accountType,
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$subscriber = User::where('email', $data['email'])->get();
if($accountType == 'individual')
{
$subscriber->newSubscription('individual', 'individual')->create($stripeToken);
// тут выкидывает ошибку
}
else
{
return 'NOT individual!!!';
}
return 'DONE!';
}
Answer the question
In order to leave comments, you need to log in
The question can be deleted, I looked at the function in the line:
$subscriber = User::where('email', $data['email'])->get();
//а надо
$subscriber = User::where('email', $data['email'])->first();
Everything is described in the error itself. You don't have newSubscription() method and you are trying to call it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question