mardi 24 novembre 2015

Laravel deprecated beforeFilter

Not to repeat the search for the user I have the following code , but laravel 5.1 beforeFilter is deprecated. how to replace it.

The function find is applied only to edit, update and destroy methods

class UserController extends Controller {

private $user;

public function __construct(){

    $this->beforeFilter('@find',['only' => ['edit', 'update', 'destroy']]);

}

public function find(Route $route){
    $this->user = User::find($route->getParameter('user'));
}

...


public function edit()
{
    return view('usuario.edit', ['user' => $this->user]);
}

public function update(UserUpdateRequest $request)
{
    $this->user->fill($request->all());
    $this->user->save();
    Session::flash('message', 'Ok update');
    return Redirect::to('/user');
}


public function destroy()
{
    $this->user->delete();
    Session::flash('message', 'delete ok');
    return Redirect::to('/user');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire