Skip to content

Commit 22ed26c

Browse files
committed
Save 1
1 parent 6c5a89b commit 22ed26c

35 files changed

+2492
-184
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Foundation\Auth\ConfirmsPasswords;
7+
8+
class ConfirmPasswordController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Confirm Password Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller is responsible for handling password confirmations and
16+
| uses a simple trait to include the behavior. You're free to explore
17+
| this trait and override any functions that require customization.
18+
|
19+
*/
20+
21+
use ConfirmsPasswords;
22+
23+
/**
24+
* Where to redirect users when the intended url fails.
25+
*
26+
* @var string
27+
*/
28+
protected $redirectTo = '/home';
29+
30+
/**
31+
* Create a new controller instance.
32+
*
33+
* @return void
34+
*/
35+
public function __construct()
36+
{
37+
$this->middleware('auth');
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
7+
8+
class ForgotPasswordController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Password Reset Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller is responsible for handling password reset emails and
16+
| includes a trait which assists in sending these notifications from
17+
| your application to your users. Feel free to explore this trait.
18+
|
19+
*/
20+
21+
use SendsPasswordResetEmails;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Foundation\Auth\AuthenticatesUsers;
7+
8+
class LoginController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Login Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller handles authenticating users for the application and
16+
| redirecting them to your home screen. The controller uses a trait
17+
| to conveniently provide its functionality to your applications.
18+
|
19+
*/
20+
21+
use AuthenticatesUsers;
22+
23+
/**
24+
* Where to redirect users after login.
25+
*
26+
* @var string
27+
*/
28+
protected $redirectTo = '/';
29+
30+
/**
31+
* Create a new controller instance.
32+
*
33+
* @return void
34+
*/
35+
public function __construct()
36+
{
37+
$this->middleware('guest')->except('logout');
38+
$this->middleware('auth')->only('logout');
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\User;
7+
use Illuminate\Foundation\Auth\RegistersUsers;
8+
use Illuminate\Support\Facades\Hash;
9+
use Illuminate\Support\Facades\Validator;
10+
11+
class RegisterController extends Controller
12+
{
13+
/*
14+
|--------------------------------------------------------------------------
15+
| Register Controller
16+
|--------------------------------------------------------------------------
17+
|
18+
| This controller handles the registration of new users as well as their
19+
| validation and creation. By default this controller uses a trait to
20+
| provide this functionality without requiring any additional code.
21+
|
22+
*/
23+
24+
use RegistersUsers;
25+
26+
/**
27+
* Where to redirect users after registration.
28+
*
29+
* @var string
30+
*/
31+
protected $redirectTo = '/thankyou';
32+
33+
/**
34+
* Create a new controller instance.
35+
*
36+
* @return void
37+
*/
38+
public function __construct()
39+
{
40+
$this->middleware('guest');
41+
}
42+
43+
/**
44+
* Get a validator for an incoming registration request.
45+
*
46+
* @param array $data
47+
* @return \Illuminate\Contracts\Validation\Validator
48+
*/
49+
protected function validator(array $data)
50+
{
51+
return Validator::make($data, [
52+
'name' => ['required', 'string', 'max:255'],
53+
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
54+
'password' => ['required', 'string', 'min:8', 'confirmed'],
55+
]);
56+
}
57+
58+
/**
59+
* Create a new user instance after a valid registration.
60+
*
61+
* @param array $data
62+
* @return \App\Models\User
63+
*/
64+
protected function create(array $data)
65+
{
66+
return User::create([
67+
'name' => $data['name'],
68+
'email' => $data['email'],
69+
'password' => Hash::make($data['password']),
70+
]);
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Foundation\Auth\ResetsPasswords;
7+
8+
class ResetPasswordController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Password Reset Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller is responsible for handling password reset requests
16+
| and uses a simple trait to include this behavior. You're free to
17+
| explore this trait and override any methods you wish to tweak.
18+
|
19+
*/
20+
21+
use ResetsPasswords;
22+
23+
/**
24+
* Where to redirect users after resetting their password.
25+
*
26+
* @var string
27+
*/
28+
protected $redirectTo = '/home';
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Foundation\Auth\VerifiesEmails;
7+
8+
class VerificationController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Email Verification Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller is responsible for handling email verification for any
16+
| user that recently registered with the application. Emails may also
17+
| be re-sent if the user didn't receive the original email message.
18+
|
19+
*/
20+
21+
use VerifiesEmails;
22+
23+
/**
24+
* Where to redirect users after verification.
25+
*
26+
* @var string
27+
*/
28+
protected $redirectTo = '/home';
29+
30+
/**
31+
* Create a new controller instance.
32+
*
33+
* @return void
34+
*/
35+
public function __construct()
36+
{
37+
$this->middleware('auth');
38+
$this->middleware('signed')->only('verify');
39+
$this->middleware('throttle:6,1')->only('verify', 'resend');
40+
}
41+
}
+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Contact;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Auth;
8+
9+
class ContactsController extends Controller
10+
{
11+
/**
12+
* Display a listing of the resource.
13+
*/
14+
public function index(Request $request)
15+
{
16+
$user = Auth::user();
17+
$contacts = $user->contacts()->paginate(10);
18+
19+
return view('contacts.index', compact('contacts'));
20+
}
21+
22+
23+
public function fetchContacts(Request $request)
24+
{
25+
if ($request->ajax()) {
26+
$search = $request->get('search');
27+
$user = Auth::user();
28+
$contacts = $user->contacts()
29+
->where(function ($query) use ($search) {
30+
$query->where('name', 'like', "%". $search. "%")
31+
->orWhere('company', 'like', "%". $search. "%")
32+
->orWhere('phone', 'like', "%". $search. "%")
33+
->orWhere('email', 'like', "%". $search. "%");
34+
})
35+
->paginate(10);
36+
37+
return view('contacts._list', compact('contacts'))->render();
38+
}
39+
40+
return null;
41+
}
42+
43+
/**
44+
* Show the form for creating a new resource.
45+
*/
46+
public function create()
47+
{
48+
return view('contacts.create');
49+
}
50+
51+
/**
52+
* Store a newly created resource in storage.
53+
*/
54+
public function store(Request $request)
55+
{
56+
$results = $request->toArray();
57+
58+
$contact = new Contact();
59+
$contact->name = $results['name'];
60+
$contact->company = $results['company'];
61+
$contact->phone = $results['phone'];
62+
$contact->email = $results['email'];
63+
$contact->user_id = Auth::id();
64+
$contact->save();
65+
66+
return redirect()->route('home');
67+
}
68+
69+
/**
70+
* Display the specified resource.
71+
*/
72+
public function show(Contact $contact)
73+
{
74+
//
75+
}
76+
77+
/**
78+
* Show the form for editing the specified resource.
79+
*/
80+
public function edit(Contact $contact)
81+
{
82+
return view('contacts.edit', compact('contact'));
83+
}
84+
85+
/**
86+
* Update the specified resource in storage.
87+
*/
88+
public function update(Request $request, Contact $contact)
89+
{
90+
$results = $request->toArray();
91+
92+
$contact->name = $results['name'];
93+
$contact->company = $results['company'];
94+
$contact->phone = $results['phone'];
95+
$contact->email = $results['email'];
96+
$contact->user_id = Auth::id();
97+
$contact->update();
98+
99+
return redirect()->route('home');
100+
}
101+
102+
/**
103+
* Remove the specified resource from storage.
104+
*/
105+
public function destroy(Contact $contact)
106+
{
107+
$contact->delete();
108+
109+
return redirect()->route('home');
110+
}
111+
}

app/Http/Controllers/Controller.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
namespace App\Http\Controllers;
44

5-
abstract class Controller
5+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6+
use Illuminate\Foundation\Validation\ValidatesRequests;
7+
use Illuminate\Routing\Controller as BaseController;
8+
9+
class Controller extends BaseController
610
{
7-
//
11+
use AuthorizesRequests, ValidatesRequests;
812
}

0 commit comments

Comments
 (0)