bekaskaki
5 days ago

different method store

Posted 5 days ago by bekaskaki

what is the difference of these two methods?

public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'name' => 'string',
            'username' => 'string|max:20|unique:users',
            'role_id' => 'required|string',
             'active' => 'string',
            ]);
       if ($validator->passes()) {
        $model = $request->all();
        $model['password'] = bcrypt($model['password']);
        User::create($model);
        return redirect($this->title)->with('success', 'New User Added!');
    }

and :

 public function store(Request $request)
    {
        $data = new User();
        $data->name = $request->name;
        $data->username = $request->username;
        $data->password = bcrypt($request->password);
        $data->role_id = $request->role_id;
        $data->active = $request->active;
    $data->save();
        return redirect($this->title)->with('success','New User Added!');
    }

Please sign in or create an account to participate in this conversation.