mercredi 28 septembre 2016

Separating methods into many controllers?

I noticed that many of the examples in the Laravel docs seem to have Controllers where the class has only one use/method.

For example, in this part of the doc, they have a UpdatePasswordController class with a single method, update():

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Controller;

class UpdatePasswordController extends Controller
{
    /**
     * Update the password for the user.
     *
     * @param  Request  $request
     * @return Response
     */
    public function update(Request $request)
    {
        // Validate the new password length...

        $request->user()->fill([
            'password' => Hash::make($request->newPassword)
        ])->save();
    }
}

Normally, I would put a method called updatePassword() in my UserController class (along with signIn(), signUp(), resetPassword(), etc.), but I'm wondering if it's better to create multiple classes, each with a single action?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire