Laravel 5.7 Email Verification Routes - php

On Laravel 5.7 Email verification feature added. But on my project i do not use the default route names and added a prefix for my own purpose. Now when i added following code to add the verify routes, it shows an error.
Auth::routes(['verify' => true]);
Error message shows that the verification.verify route does not exists. Where can i update this route name in my project? Or is it the only way to use this feature is to follow the default Auth Route names?
Project Source Code Is available at https://github.com/nasirkhan/laravel-starter/tree/l57

Instead of using Auth::routes(['verify' => true]); just use Auth::routes(); and manually add these routes:
Route::get('email/verify', 'Auth\VerificationController#show')->name('verification.notice');
Route::get('email/verify/{id}', 'Auth\VerificationController#verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController#resend')->name('verification.resend');
Then customise as you want :)

Anyone who gets here and is looking for tompec's version for the latest Laravel, use the below. Notice the addition of /{hash}.
$this->get('email/verify', 'Auth\VerificationController#show')->name('verification.notice');
$this->get('email/verify/{id}/{hash}', 'Auth\VerificationController#verify')->name('verification.verify');
$this->post('email/resend', 'Auth\VerificationController#resend')->name('verification.resend');

When you want to change the route throught which the verification process will be done you must change all the way the verification process work.
Email verification notification process
During the registration process an event Illuminate\Auth\Events\Registered is emit. Laravel come whith a listener Illuminate\Auth\Listeners\SendEmailVerificationNotification which is already registered in the App\Providers\EventServiceProvider.
After implementing the MustVerifyEmail interface when the Registered event is emit the SendEmailVerificationNotification listener will check if the App\User have already use the Illuminate\Contracts\Auth\MustVerifyEmail trait by checking if the user create is an instance of MustVerifyEmail if that is the case it will call the sendEmailVerificationNotification method on the user which get the implementation of this method when it use the Illuminate\Auth\MustVerify trait.
Customization of the verification route
To change the behavior of the verification process you can customize the sendEmailVerificationNotification to emit a custom event which can have a custom listener in which you will perform all the verification stuff and notify the user by email in which you will send the custom route through which the verification process will be done

In my case, I had the same issue and I was receiving the message
InvalidArgumentException
Attribute [auth] does not exist.
at vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php:92
I've solved it updating my composer executable file and laravel local files.
composer global self-update
composer update
It seems that my composer executable was using and old version of laravel installer.

Related

laravel7, is there mindmap for login process?

I am creating my first package with Laravel 7.
Idea is make login and register process inside it.
Login and Register forms are working,
and process logic work aswell.
When I am calling them from route-file directly Blade form.
But
I have added login and register controller.
After login form send request to logged in,
comes issues:
Issue 1) Trait Illuminate\Foundation\Auth\AuthenticatesUsers
not found.
Tried so far:
added "laravel/ui" to Composer.json inside my package.
---- Edit ---
I found "illuminate/auth" from Github/Laravel/framework/blob/7.x/src/illuminate/Auth/composer.json
namespace is same as error.
installed but still same error.
Q) Do I miss some other package which calls User trait ?
Thanks Mika.
--- EDIT ----
I have been searcing few days to way to do it.
Found https://laracasts.com/discuss/channels/laravel/create-laravel-route-inside-another-composer-packages
But it is for Larave 5.X, is it still valid way to fix this problem ?
If you want to use Laravel's built in authentication, this is how you set it up:
Run
composer require laravel/ui
Then run
php artisan ui:auth
and
php artisan migrate
If you want to use Vue with the UI scaffolding you can run php artisan ui vue --auth instead of php artisan ui:auth.
So I'd recommend to undo what you did (seems like you didn't run through the install steps properly) and then follow the steps above. More info in the official documentation.
The trait you're trying to use is in fact inside laravel/ui, so you should still require this package in your composer.json: https://github.com/laravel/ui/blob/2.x/auth-backend/AuthenticatesUsers.php
I would also try running composer dump-autoload after installing the laravel/ui package (this should clear any cached autoloaders).
Also, please don't forget to properly import the AuthenticatesUsers trait in your controller:
use Illuminate\Foundation\Auth\AuthenticatesUsers;
...
class LoginController extends Controller
{
use AuthenticatesUsers;
...
}

Why I got error 404 when I try to handle stripe event with laravel and spatie stripe webhooks packge?

I'm newbie with this package and I've some issue that I don't understand...
I follow exactly the readme file and I got a 404 error when I try to handle the stripe event with Stripe CLI.
I redirect the event with :
stripe listen --events checkout.session.completed --skip-verify --forward-to https://backend.bnb.local/api/webhook/checkout
and I have that in return :
> Ready! Your webhook signing secret is whsec_mSz72pL***************641iqZ7 (^C to quit) 2020-06-09 16:38:09 --> \checkout.session.completed\ [\evt_1Gs8aaLGS8l*******7PkQZPgp3\] 2020-06-09 16:38:09 <-- [404] POST https://backend.bnb.local/api/webhook/checkckout [\evt_1Gs8aaLGS*****k7PkQZPgp3\]
In my routes/api files :
Route::stripeWebhooks('https://backend.bnb.com/api/webhook/checkout');
In my EventServiceProvider :
protected $listen = [ 'stripe-webhooks::checkout.session.completed' => [ App\Listeners\HandleSubscriptions::class ] ];
I probably do something wrong but I don't find why...
[UPDATE]
I finally found the problem...
I've writing the wrong route. I change for :
Route::stripeWebhooks('webhook/checkout');
And I've put in the Auth:api middelware too. So I change it...
It looks like the domain you specify in your stripe listen CLI command doesn't match the domain you're passing into the route configuration. In your Laravel routing config I would omit the domain entirely:
Route::stripeWebhooks('/api/webhook/checkout');
You might also try running php artisan route:list to see how that route is configured. My guess is that because you passed the domain name, the route won't match the Host header that the stripe CLI will pass (Host: backend.bnb.local) so the solution is to either omit the domain, or specify the correct domain so Laravel's routing can handle the rest.

Class verified does not exist, Email verification Laravel 5.7

I have updated my Laravel project from 5.6 to 5.7. Laravel 5.7 comes with the new email verification so I tried to build that in my new project.
I folowed the instructions on the update guide from the Laravel docs, but after registering a new user on my site, I receive the message: Class verified does not exist. It does send me an email, so that part works just fine. But I think I'm missing something in my middleware, because the docs say we have to add: Auth::routes(['verify' => true]); instead of the original Auth::routes();
Did anybode had the same problem like I did?
Ensure that you have registered the verified middleware in App\Http\Kernel.php:
protected $routeMiddleware = [
...
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,

Auth::logout() gives error if used in login page(without login). Laravel 5.5

I'm working with laravel 5.5. I just have little problem about Auth::logout() function. This function works fine but if I use this route path (write manually) in login page (unlogged user) this will give me error like this. What do I have to do for prevent this error message?
The logout route, is by default a POST route, trying to reach it via typing in an address would cause a GET request which would be MethodNotAllowedHttpException. (Assuming you registered the routes via Route::auth())

Add syslog handler in Laravel for paperTrail .

How could i link Laravel log files to PaperTrial ?
According to this article :
http://mattstauffer.co/blog/laravel-forge-logging-with-papertrail#step-4-add-a-syslog-handler
I followed steps and reached to step 4 putting Syslog Monolog handler in the /app/route.php file ,went to PaperTrial dashboard but i didn't see any output.
Any help ? thanks.
For Laravel 5.1 after setting up the forge, you should add to bootstrap/app.php file the following code just before the return of the $app variable
$app->configureMonologUsing(function($monolog){
$monolog->pushHandler(new Monolog\Handler\SyslogHandler('papertrail'));
});
return $app;
The parameter (in this case 'papertrail') can be whatever you want to, this name will show on the papertail's event screen.
I have it working using the standard logging facility instead of Monolog. This way there is nothing extra to install. Just add this to rsyslogd's conf:
### Laravel Log
$InputFileName /path/to/vhost/dir/app/storage/logs/laravel.log
$InputFileTag laravel-errors-domain.com:
$InputFileStateFile state-laravel-errors-domain.com
$InputFileSeverity error
$InputRunFileMonitor
And make sure that this log gets included in the send action, if you are not sending everything.
Then issue
service rsyslog restart
From my experience using Laravel 5.2.* with Forge, Step 4 from that article is not necessary anymore. All you have to do after Step 3 is set your Environment .env settings in Forge to APP_LOG=syslog for each site you want to use with papertrail.
However, this means that Laravel will not log to laravel.log anymore in this environment. But, in other environments (e.g. dev environment) you could of course continue logging to laravel.log by simply not making any changes to the .env file there.

Categories