path = config('app.client_path'); $ads = Advertisements::where('status', 1)->where('parent_advertisement',0)->get(); $headerMenuItems = Menuitems::where(['parent_menu' => 0, "status" => 1, "menulocations_id" => 1])->with('children')->orderBy('display_order')->get(); $footerMenuItems = Menuitems::where(['parent_menu' => 0, "status" => 1, "menulocations_id" => 2])->with('children')->orderBy('display_order')->get(); $latestNews = News::where('status', 1)->inRandomOrder()->limit(4)->get(); View::share([ 'ads' => $ads, 'headerMenuItems' => $headerMenuItems, 'footerMenuItems' => $footerMenuItems, 'latestNews' => $latestNews ]); } public function login() { return view($this->path.'.auth.login'); } public function register() { return view($this->path.'.auth.registration'); } public static function store(Request $request) { dd($request->all()); $request->validate([ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]); User::create([ 'name' => $request->name, 'email' => $request->email, 'password' => bcrypt($request->password), 'username' => $request->name ]); $credentials = $request->only('email', 'password'); if (Auth::attempt($credentials)) { $request->session()->regenerate(); return response()->json([ 'success' => true, 'message' => 'You have successfully logged in!', 'redirect_url' => route('home') ]); } return response()->json([ 'success' => false, 'message' => 'The provided credentials do not match our records.' ]); } public static function authenticate(Request $request){ $credentials = $request->validate([ 'email' => ['required', 'string', 'email', 'max:255'], 'password' => ['required', 'string', 'min:8'], ]); $remember = $request->has('remember_me') ? true : false; if (Auth::attempt($credentials, $remember)) { $request->session()->regenerate(); return response()->json([ 'success' => true, 'message' => 'You have successfully logged in!', 'redirect_url' => route('home') ]); } return response()->json([ 'success' => false, 'message' => 'The provided credentials do not match our records.' ]); } public static function logout(Request $request){ Auth::logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); return redirect()->route('userLogin'); } }