laravel 5.2 pass data to registration view

。_饼干妹妹 提交于 2019-12-23 11:58:27

问题


I'm using laravel 5.2 and I wrote this command to automatically add routes and views of authentication:

php artisan make:auth

Now I want to pass data to registration view but I don't find where to do that, I assume that it should be with a code like that:

Route::get('register', 'Auth\AuthController@showRegistrationForm');

But in routes.php I have this:

Route::auth();

And in Auth\AuthController there are only two methods:

  • validator
  • create

回答1:


register user class is in this file

\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php

In laravel 5.2 in auth controller you see

use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

and in this file see

   use AuthenticatesUsers, RegistersUsers {
    AuthenticatesUsers::redirectPath insteadof RegistersUsers;
    AuthenticatesUsers::getGuard insteadof RegistersUsers;
}

and RegistersUsers class is in

\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php

If you use phpstorm ide you can go to the class name and press ctrl + left click and php storm open your class .




回答2:


I new in Laravel, that's why my answer might be not right.

You can see what routes set "Route::auth()" in class Illuminate\Routing\Router in method auth().

AuthController use trait AuthenticatesAndRegistersUsers, this trait use trait RegistersUsers in namespace Illuminate\Foundation\Auth.

You can redeclare method showRegistrationForm() in AuthController:

public function showRegistrationForm()
{
    $data['info'] = "info";

    if (property_exists($this, 'registerView')) {
        return view($this->registerView);
    }

    return view('auth.register', $data);
}


来源:https://stackoverflow.com/questions/35389232/laravel-5-2-pass-data-to-registration-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!