doujiepin5547 2016-10-26 09:07
浏览 52

注册的用户数据不会保存到数据库中。 Laravel 5.2

I tried to implement role base authentication. Authentication is done correctly. If the user is admin only then he can register a new employee. But the matter is the data put into registration form is not saved to database. Route redirections are correct but data is not saved. I am using builtin auth system of laravel 5.2.

Route:: get('/register',['middleware'=> 'roles', function(){

    return view('auth.register');
}]);

middleware:

public function handle($request, Closure $next)
    {
        if ($request->user()==null)
        {
            return redirect('/login');

        } 
        if (!$request->user()->isAdmin()){
            return redirect('books');
        }

        return $next($request);

    }
}

User Model:

  public function roles(){
        return $this->belongsToMany('App\Role','roles_users', 'user_id', 'role_id');
    }
    public function isAdmin() {
        return in_array(2, $this->roles()->pluck('role_id')->all());
    }

if I remove the middleware then the registered data is saved properly.

  • 写回答

1条回答 默认 最新

  • doukezi4606 2016-10-26 16:40
    关注

    I solved my problem. In built in AuthController there is a constructor with predefined middleware. Deleted it. My code works as I wanted.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度