Laravel 5.1 flash message after register - laravel

I'm using Laravel's out of the box authentication, which came with laravel 5.
Basically, my AuthController is empty, and all the logic happens within the AuthenticatesAndRegistersUsers trait.
Now I want to flash a message only after a user is registered.
I can change the trait, but it's not recommended, and might not work on future versions of Laravel.
There is a way to run my custom code from the Controller after user registers?

Just copy the trait into your controller, Laravel will use the method in your controller instead of the trait because it's kind of inheritance, that way you won't touch the trait and you will be sure that the method of the flash message will work on any version of Laravel

Related

Laravel Custom Request Class - can I define Middleware here?

So, for me the main 2 methods of adding middleware are in the routes files, api.php and web.php, or alternatively in the constructor of any Controller class.
However it occurred to me that there might be situations where I want to choose for a certain Request subclass to have some middleware applied to it. I haven't seen documentation for this. Is there a way to define middleware in these custom Requests?
For clarity, I'm referring to the Request classes that get made when you do php artisan make:request

How to conditionally add middleware in another middleware Laravel

I'm wondering how I can add middleware conditionally in another middleware in my Laravel project.
I noticed that Laravel Nova adds middleware in this way in the NovaCoreServiceProvider
$this->app->make(HttpKernel::class)->pushMiddleware(ServeNova::class);
I am trying to accomplish this outside of the scope of a service provider, where you do not have access to $this->app, so I tried it this way:
$container = app();
$container->make(HttpKernel::class)->pushMiddleware(MyMiddleware::class);
But this doesn't seem to work. Is it possible to push middleware to the stack from a middleware? If so, how can I accomplish this?
The only reason I am doing it this way as opposed to just simply registering it normally is to prevent the unnecessary loading of resources (which the middleware is responsible for triggering).

Call a function after login fails or success laravel 5.3

I want to call a custom function when the user success in login and another when fails but i can't find the solution, i use laravel 5.3 and make:auth method.
I have the LoginController but is almost emtpy.
The route for login post:
Route::post('login', ['as' => 'login.post', 'uses' => 'Auth\LoginController#login']);
I have a helper function called flash('The messaje') that sends an jquery alert on the view, i use in controllers and works fine, but i don't know where put this code to show an alert if the auth login fails and success.
Thanks!
As by default LoginController uses AuthenticatesUsers trait, all you need to is to write custom methods sendLoginResponse and sendFailedLoginResponse. You can of reuse trait methods and to add only custom mode you want to execute.

Best practice for adding captcha to user registration

I'm using Laravel 5.1 with Bestmomo Scafold for user account management and I'm trying to add BotDetect captcha by following this quickstart tutorial. I was able to get it to work but to do so I had to modify the Illuminate\Foundation\Auth\RegistersUsers trait as opposed to the "ExampleController" that the tutorial uses.
I don't want to edit a vendor file, but I'm new to PHP so I'm wondering what alternative there is?
create a trait that extends from the one that you need, make the changes there and make your class uses the new trait and you will never touch vendor folder.

Where is the Registrar Services in Laravel 5?

I added couple of fields to my user table and everywhere I read it said I also need to update the new fields in the app/Services/Registrar.php file. But I cannot find the Services folder anywhere! This is a new installation in Laravel 5 and here is the screen shot of my directory structure:
What happened to the Services Folder? When I test, I can see that the User::create() works but I dont know where its declared since I cant find the Registrar.php file.
I added couple of fields to my user table and everywhere I read it said I also need to update the new fields in the app/Services/Registrar.php file.
This was removed in Laravel 5.1.
https://laravel.com/docs/5.1/upgrade#upgrade-5.1.0
Secondly, the App\Services\Registrar class used in Laravel 5.0 is no longer needed. You can simply copy and paste your validator and create method from this class directly into your AuthController. No other changes should need to be made to these methods; however, you should be sure to import the Validator facade and your User model at the top of your AuthController.
You are using 5.1 version and it doesn't have such directory or service. This version uses AuthenticatesAndRegistersUsers traits for registering users.

Resources