You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.5 KiB

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Contact;
use App\Models\Referral;
use App\Models\Subscription;
use App\Models\Service;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
class HomeController extends Controller
{
public function indexAdmin()
{
if(Auth::check()){
$service= Service::where('status',true);
$contact= Contact::all();
$subscription= Contact::all();
$contacts = Contact::paginate(config('custom.per_page'));
// $referrals=Referral::paginate(config('custom.per_page'));
return view('admin.index', compact( 'service', 'contact', 'contacts','subscription'));
}
return view('admin.login');
}
public function getLogin()
{
if(Auth::check()){
return redirect('admin/index');
}
return view('admin.login');
}
public function postLogin()
{
$this->validate(request(),[
'email'=>'required',
'password'=>'required',
]);
// dd(\request()->all());
if (Auth::attempt(['email'=>request('email'),'password'=>request('password')],request()->has('remember'))){
return redirect('admin/index');
}
// Session::flash('success','Invalid Credential!');
return redirect('login')->withErrors(['Invalid Credentials!']);
}
public function admin()
{
if(Auth::check()){
return view('admin.index');
}
}
public function getLogout()
{
Auth::logout();
return redirect('login');
}
public function change_password(){
return view('admin.change_password_form');
}
public function update_password(Request $request){
$request->validate([
'old_password' => 'required',
'password' => 'required|min:8|confirmed',
]);
$user = auth()->user();
if(Hash::check($request->old_password,$user->password)){
$user = User::findorfail($user->id);
if($user->update(['password' => Hash::make($request->password)])){
return redirect()->back()->with('success','Password is successfully updated.');
}
}
return redirect()->back()->with('custom_error','Your old password is incorrect! Please try again.');
}
}