Spatie Laravel Welcome Notification - laravel

did someone encounter this problem when trying to configure the welcome notification using Spatie
I don't have any WelcomeNotification Model. do i need to make one?

I suppose you have created a notification in the model folder because you are using $user->notify(new WelcomeNotification($validUntil)). And, you are passing WelcomeNotification model into notify as a parameter instead of a notification class object, which causes error.
You need to create the notification in the app/Notifications. So, when you run this command it will automatically create the WelcomeNotification in the app/Notifications folder.
php artisan make:notification WelcomeNotification
Now, import use App\Notifications\WelcomeNotification; in the User model.

Related

How to create modular in laravel?

I want to create a modular to create a controller and a model.
Of course, the model is pre-created.
php artisan module:make-controller Admin\ReportController Report --model=Report
I see this message
The "--model" option does not exist.
I assume you used nWidart Modules, so the answer is you can not use --model option because nWidart Modules doesn't support that option/parameter. You need run another command to create a model, an example:
php artisan module:make-model Report Admin
Report is model name, and Admin is module name
check it out for more module commands

How to attach middleware to an existing named route from a package in laravel 5?

I'm trying to extend an existing application without modifying its source code.
The application has a named route called wizard-add.
Is there a way to register \MyPackage\MyMiddleware with the existing route?
I tried attaching it via Route::getRoutes()->getByName('wizard-add')->middleware(\MyPackage\MyMiddleware::class); but since packages are registered before the routes are read, Route::getRoutes() returns an empty collection.
Thank you!
Since I didn't find a way to solve this, I extended the app's controllers and put my logic inside.
namespace MyPackage\Controllers;
use App\Controllers\WizardController;
class MyPackageWizardController extends WizardController { ... }
and then in my service provider's register() method:
$this->app->bind(WizardController::class, MyPackageWizardController::class);
So everytime the app attempts to instantiate WizardController, it instantiates MyPackageWizardController instead. I don't know if there are any drawbacks but so far this has been working perfectly for me.

How to override any Model of vendor folder in laravel

I am using MongoDB as database so I need to change model of package tzsk\payu as using original is giving me following error
Call to a member function prepare() on null
I tried excluding original model and overriding using composer it doesn't work.
The only way would be if the package offered the option to use a custom model, like Passport is doing.
As far as I can see, there does not seem to be a way to do that. Thus you'd need to fork the package and edit the Model yourself.

I can't seem to access my Auth inside a vendor package

I had a Laravel app that I created, then I added another Laravel package for Oauth2 for a CRM.
This created a vendor and migration for DB. I tested it and it worked, I authenticated my CRM.
Now I would like to have that record be tied to the user_id in the Auth scaffold that I created with composer make:auth
However, when I try to get the current user from inside of those vendor files, it is not pulling in that information and is giving me errors.
I think this may be a namespace issue, but maybe it could be a guard or middleware. I am not sure. I am pretty laravel
I have tried a handful of other solutions, but I wasn't sure if those were tied to my specific issue
<?php
namespace Djaxho\LaravelInfusionsoftOauth2\Http\Controllers;
//namespace App\Http\Controllers\Auth;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use Djaxho\LaravelInfusionsoftOauth2\Infusionsoft;
use Illuminate\Support\ServiceProvider;
//use Illuminate\Support\Facades\Auth;
class AuthorizeInfusionsoftApiController extends BaseController
'''
print Auth::user()->id;
I see that it is in its own namespace, is this what is the issue, laravel is not looking outside?
I get this error:
Class 'Djaxho\LaravelInfusionsoftOauth2\Http\Controllers\Auth' not
found
Their page says it pretty straightforward on what to do.
https://packagist.org/packages/djaxho/laravel-infusionsoft-oauth2
Installation (These instructions are for an 'alerady set-up' laravel
project with a functioning database set up) Add the service provider
for laravel by adding the following line to your 'providers' array in
the file congig/app.php
Djaxho\LaravelInfusionsoftOauth2\LaravelInfusionsoftOauth2ServiceProvider::class,
And add
use Djaxho\LaravelInfusionsoftOauth2\Infusionsoft;
to your model where you are calling the auth from.
That being said, I dont know if this package handles auth seperately or doesnt. In that case you should use the laravel facade,
use Illuminate\Support\Facades\Auth
You need to give you routes in your package web middleware and it will works fine
.

Laravel 5.3 Notifications Seeder

What I am trying to acheive - is create a database seeder for Laravel Notifications. As far as i am using database to store my notifications, there should be a way to achieve it. I am creating Factory model :
$user->notify(new NotificationEvent($event));
In fact it creates a notification in database, but artisan returns with error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Illuminate\Support\Facades\Notification::save()
Anybody knows what to do?
This seems to be a namespace issue, please try the following, place the class reference on top of your seed class:
use Notification;

Resources