The effects of adding a Service Layer to a Laravel application

I also switched to Laravel coming from Zend and missed my Services. To sooth myself I have implemented a Service namespace which sits in namespace App\Services. In there I do all my Model or data handeling I don't want to see in my controller etc.

An example of my controller layout:

<?php
namespace App\Http\Controllers;

use App\Services\Contact as ContactService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class IndexController extends Controller
{

    /**
     * Create a new controller instance.
     *
     * @param Request $request
     * @return void
     */
    public function __construct(Request $request)
    {
        $this->_request  = $request;
    }

    /**
     * Standard contact page
     * 
     * @return contact page
     */
    public function contact(ContactService $contactService)
    {
        $errors  = null;
        $success = false;
        if ($this->_request->isMethod('post')) {
            $validator            = $contactService->validator($this->_request->all());
            if ($validator->fails()) {
                $errors = $validator->errors();
            } else {
                $contactService->create($validator->getData());
                $success = true;
            }
        }
        return view('pages/contact', ['errors' => $errors, 'success' => $success]);
    }
}

The services return validators, handle cruds, basically do everything that I don't want to see in my Controller just like I had it in my Zend projects.

Example of Service:

<?php
namespace App\Services;

use Validator;
use Mail;
use App\Models\Contact as ContactModel;

class Contact
{

    /**
     * Get a validator for a contact.
     *
     * @param  array $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    public function validator(array $data)
    {
        return Validator::make($data, [
                'email'     => 'required|email|max:255',
                'phone'     => 'max:255',
                'firstName' => 'required|max:255',
                'lastName'  => 'required|max:255',
                'message'   => 'required'
        ]);
    }

    /**
     * Create a new contact instance after a valid form.
     *
     * @param  array $data
     * @return ContactModel
     */
    public function create(array $data)
    {
        //Handle or map any data differently if needed, just for illustration
        $data = [
            'email'     => $data['email'],
            'firstName' => $data['firstName'],
            'lastName'  => $data['lastName'],
            'language'  => $data['language'],
            'phone'     => $data['phone'],
            'message'   => $data['message']
        ];
        
        // Send an email
        Mail::send('emails.contact', ['data' => $data], function ($m) use ($data) {
            $m->from(config('mail.from.address'), config('mail.from.name'));
            $m->to(env('MAIL_TO', '[email protected]'), env('MAIL_TO'))->subject('Contact form entry from: ' . $data['firstName']);
        });
        
        return ContactModel::create($data);
    }
}

See this post: “Design Pattern : Service Layer with Laravel 5” @Francoiss https://m.dotdev.co/design-pattern-service-layer-with-laravel-5-740ff0a7b65f.. in addition to the above answer you can also encapsulate the validation code inside a separate validator class