Hello.
Not so long ago began to learn Laravel 5.3. Before that, I used a simple CodeIgniter 3 framework, where, with the organization of the code, in principle, everything is clear: you make yourself a cloud of models for all occasions and that's it. In Laravel, there are all sorts of service providers, service containers, facades, contracts, middleways ... and it’s quite difficult to figure out all this by just docks. You start to read about the service containers, and there suddenly begin to refer to service providers. You decide and read about them, and there they suddenly refer to something else. Thus, the Wheel of Samsara closes and there is a desire to go to bed on the sofa.
See it. Here I have a registration, after which the user is sent an email with a link, clicking on which he should activate the account. Making it work is easy; the only question is how aesthetic it will turn out.
I read that in controllers, accessing a database is a bad tone, and generally keep your controllers thin and models fat . But how, in this case, to process approximately the situation where I create a new account and then send an email to activate the account? How and where to take it out of the controller?
<?php namespace App\Http\Controllers; use Validator; use Illuminate\Support\Facades\Mail; use App\Http\Controllers\Controller; /* Eloquent */ use App\User; /* Requests */ use App\Http\Requests\Register; /* Mailables */ use App\Mail\ConfirmRegistration; class RegisterController extends Controller { /** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function store(Register $request) { $created_user = User::create([ 'name' => $request->input('name'), 'email' => $request->input('email'), 'password' => $request->input('password'), ]); Mail::to($request->input('email'))->send(new ConfirmRegistration($created_user)); return $created_user; } } The second question from the same song is about organizing the code. I have classes that work with the API of various sites (VK, Imgur, etc.). Each such class has approximately the same set of methods ( auth() , refreshToken() , api() , etc.). Just ordinary classes in the Classes directory inside the app directory. Is it possible to take them out and convert them to something that is supported by the framework (such as a service provider) out of the box? Will boiling oil boiler wait for those who will call methods of similar classes inside the controller? Or how from a question above they should be taken out somewhere?
Thanks to everyone who at least reads this sheet of text, and special thanks to everyone who answers.