samedi 21 octobre 2017

Laravel data is not saving in user table .and also not going postRegister function. please help me

am registering use through Auth controller (the auth controller use use AuthenticatesAndRegistersUsers, ThrottlesLogins). when is click on register function it go

use toAuthenticatesAndRegistersUsers 

then authcontroller but not going in postRegister. :( also not showing any error.please help me. here is AuthController

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Models\Employee;
use App\Role;
use Validator;
use Illuminate\Support\Facades\Hash;
use Eloquent;
use Mail; 
use Session;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }

    public function showRegistrationForm()
    {
        $roleCount = Role::count();
        if($roleCount != 0) {
            $userCount = User::count();
            if($userCount == 0) {
                return view('auth.register');
            } else {
                return redirect('login');
            }
        } else {
            return view('errors.error', [
                'title' => 'Migration not completed',
                'message' => 'Please run command <code>php artisan db:seed</code> to generate required table data.',
            ]);
        }
    }
       public function showLoginForm()
        {
            $roleCount = Role::count();
            if($roleCount != 0) {
                $userCount = User::count();
                if($userCount == 0) {
                    return redirect('register');
                } else {
                    return view('auth.login');
                }
            } else {
                return view('errors.error', [
                    'title' => 'Migration not completed',
                    'message' => 'Please run command <code>php artisan db:seed</code> to generate required table data.',
                ]);
            }
        }

        /**
         * Get a validator for an incoming registration request.
         *
         * @param  array  $data
         * @return \Illuminate\Contracts\Validation\Validator
         */
        protected function validator(array $data)
        {
            return Validator::make($data, [
                'name' => 'required|max:255',
                'email' => 'required|email|max:255',
                'password' => 'required|min:6|confirmed',
            ]);
        }

        /**
         * Create a new user instance after a valid registration.
         *
         * @param  array  $data
         * @return User
         */
        protected function create(array $data)
        {
            // TODO: This is Not Standard. Need to find alternative
            Eloquent::unguard();

            $employee = Employee::create([
                'name' => $data['name'],
                'designation' => "Admin",
                'mobile' => "85888",
                'mobile2' => "",
                'email' => $data['email'],
                'gender' => 'Male',
                'dept' => "1",
                'city' => "Lahore",
                'address' => "Pakistan",
                'about' => "About user / biography",
                'date_birth' => date("Y-m-d"),
                'date_hire' => date("Y-m-d"), 
                'date_left' => date("Y-m-d"),
                'salary_cur' => 0,
            ]);

            $user = User::create([
                'name' => $data['name'],
                 'firstname' => $data['firstname'],
                  'lastname' => $data['lastname'],
                   'address' => $data['address'],
                    'mobile_number' => $data['mobile_number'],
                     'deals' => $data['deals'],
                       'city_id' => $data['city_id'],
                         'plaza_id' => $data['plaza_id'],
                'email' => $data['email'],
                 'pin_code'=>date('U'),
                'password' => Hash::make($data['password']),
                'context_id' => $employee->id,
                'type' => "ADMIN",
            ]);
            $role = Role::where('name', 'ADMIN')->first();
            $user->attachRole($role);
                 //  email for  Shop Owner
            Mail::send('emails.email', ['user' => $user], function ($m) use ($user) {
             //   $m->from('hello@app.com', 'Your Application');

              $m->to($user->email,$user->name)->subject('Welcome at Classified!');
           });

    // email for administration
        /* Mail::send('emails.email', ['user' => $user], function ($m) use ($user) {
             //   $m->from('hello@app.com', 'Your Application');

              $m->to($user->email,$user->name)->subject('Welcome at Classified!');
           });
    */

         Session::flash('success', "Your request has been sent for verification by Master Networks !!!");

            return $user;
        }
    }

here is may route

Route::get('/registers', 'Frontend\RegisterController@index');
    Route::post('/registers', 'Auth\AuthController@postRegister');

here is RedirectsUsers

<?php

namespace Illuminate\Foundation\Auth;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
trait RegistersUsers
{
    use RedirectsUsers;

    /**
     * Show the application registration form.
     *
     * @return \Illuminate\Http\Response
     */
    public function getRegister()
    {
        return $this->showRegistrationForm();
    }

    /**
     * Show the application registration form.
     *
     * @return \Illuminate\Http\Response
     */
    public function showRegistrationForm()
    {
        if (property_exists($this, 'registerView')) {
            return view($this->registerView);
        }

        return view('auth.register');
    }

    /**
     * Handle a registration request for the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function postRegister(Request $request)
    {

        return $this->register($request);
    }

    /**
     * Handle a registration request for the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function register(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            $this->throwValidationException(
                $request, $validator
            );
        }

        Auth::guard($this->getGuard())->login($this->create($request->all()));

        return redirect($this->redirectPath());
    }

    /**
     * Get the guard to be used during registration.
     *
     * @return string|null
     */
    protected function getGuard()
    {
        return property_exists($this, 'guard') ? $this->guard : null;
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire