Skip to content

Commit fa3082f

Browse files
committed
add getting started guide files
1 parent 233069c commit fa3082f

File tree

66 files changed

+250559
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+250559
-525
lines changed

app/Data/Models/Link.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Data\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
/**
8+
* @author Abed Halawi <[email protected]>
9+
*
10+
* @property-read string url
11+
* @property-read string title
12+
* @property-read string description
13+
*/
14+
class Link extends Model
15+
{
16+
protected $fillable = ['url', 'title', 'description'];
17+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Domains\Http\Jobs;
4+
5+
use Lucid\Units\Job;
6+
7+
class RedirectBackJob extends Job
8+
{
9+
/**
10+
* @var bool
11+
*/
12+
private $withInput;
13+
14+
/**
15+
* Create a new job instance.
16+
*
17+
* @param bool $withInput
18+
*/
19+
public function __construct($withInput = false)
20+
{
21+
$this->withInput = $withInput;
22+
}
23+
24+
/**
25+
* Execute the job.
26+
*/
27+
public function handle()
28+
{
29+
$back = back();
30+
31+
if ($this->withInput) {
32+
$back->withInput();
33+
}
34+
35+
return $back;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Domains\Http\Tests\Jobs;
4+
5+
use App\Domains\Http\Jobs\RedirectBackJob;
6+
use Tests\TestCase;
7+
8+
class RedirectBackJobTest extends TestCase
9+
{
10+
public function test_redirect_back_job()
11+
{
12+
$this->markTestIncomplete();
13+
}
14+
}

app/Domains/Link/Jobs/SaveLinkJob.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Domains\Link\Jobs;
4+
5+
use Lucid\Units\Job;
6+
use App\Data\Models\Link;
7+
8+
class SaveLinkJob extends Job
9+
{
10+
private $url;
11+
private $title;
12+
private $description;
13+
14+
/**
15+
* Create a new job instance.
16+
*
17+
* @param $url
18+
* @param $title
19+
* @param $description
20+
*/
21+
public function __construct($url, $title, $description)
22+
{
23+
$this->url = $url;
24+
$this->title = $title;
25+
$this->description = $description;
26+
}
27+
28+
/**
29+
* Execute the job.
30+
*
31+
* @return Link
32+
*/
33+
public function handle()
34+
{
35+
$attributes = [
36+
'url' => $this->url,
37+
'title' => $this->title,
38+
'description' => $this->description,
39+
];
40+
41+
return tap(new Link($attributes))->save();
42+
}
43+
}

app/Domains/Link/Requests/AddLink.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Domains\Link\Requests;
4+
5+
use Illuminate\Support\Facades\Auth;
6+
use Illuminate\Foundation\Http\FormRequest;
7+
8+
class AddLink extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*
13+
* @return bool
14+
*/
15+
public function authorize()
16+
{
17+
return Auth::check();
18+
}
19+
20+
/**
21+
* Get the validation rules that apply to the request.
22+
*
23+
* @return array
24+
*/
25+
public function rules()
26+
{
27+
return [
28+
'title' => ['required', 'max:255'],
29+
'url' => ['required', 'url', 'max:255'],
30+
'description' => ['required', 'max:255'],
31+
];
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Domains\Link\Tests\Jobs;
4+
5+
use Faker\Factory as Fake;
6+
use Tests\TestCase;
7+
use App\Data\Models\Link;
8+
use App\Domains\Link\Jobs\SaveLinkJob;
9+
use Illuminate\Foundation\Testing\RefreshDatabase;
10+
11+
class SaveLinkJobTest extends TestCase
12+
{
13+
use RefreshDatabase;
14+
15+
public function test_save_link_job()
16+
{
17+
$f = Fake::create();
18+
19+
$url = $f->url;
20+
$title = $f->sentence;
21+
$description = $f->paragraph;
22+
23+
$job = new SaveLinkJob($url, $title, $description);
24+
$link = $job->handle();
25+
26+
$this->assertInstanceOf(Link::class, $link);
27+
$this->assertEquals($url, $link->url);
28+
$this->assertEquals($title, $link->title);
29+
$this->assertEquals($description, $link->description);
30+
}
31+
}

app/Features/AddLinkFeature.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Features;
4+
5+
use Lucid\Units\Feature;
6+
use App\Domains\Link\Requests\AddLink;
7+
use App\Domains\Link\Jobs\SaveLinkJob;
8+
use App\Domains\Http\Jobs\RedirectBackJob;
9+
10+
class AddLinkFeature extends Feature
11+
{
12+
public function handle(AddLink $request)
13+
{
14+
$this->run(SaveLinkJob::class, [
15+
'url' => $request->input('url'),
16+
'title' => $request->input('title'),
17+
'description' => $request->input('description'),
18+
]);
19+
20+
return $this->run(new RedirectBackJob());
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Http\Requests\Auth\LoginRequest;
7+
use App\Providers\RouteServiceProvider;
8+
use Illuminate\Http\Request;
9+
use Illuminate\Support\Facades\Auth;
10+
11+
class AuthenticatedSessionController extends Controller
12+
{
13+
/**
14+
* Display the login view.
15+
*
16+
* @return \Illuminate\View\View
17+
*/
18+
public function create()
19+
{
20+
return view('auth.login');
21+
}
22+
23+
/**
24+
* Handle an incoming authentication request.
25+
*
26+
* @param \App\Http\Requests\Auth\LoginRequest $request
27+
* @return \Illuminate\Http\RedirectResponse
28+
*/
29+
public function store(LoginRequest $request)
30+
{
31+
$request->authenticate();
32+
33+
$request->session()->regenerate();
34+
35+
return redirect(RouteServiceProvider::HOME);
36+
}
37+
38+
/**
39+
* Destroy an authenticated session.
40+
*
41+
* @param \Illuminate\Http\Request $request
42+
* @return \Illuminate\Http\RedirectResponse
43+
*/
44+
public function destroy(Request $request)
45+
{
46+
Auth::logout();
47+
48+
$request->session()->invalidate();
49+
50+
$request->session()->regenerateToken();
51+
52+
return redirect('/');
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Providers\RouteServiceProvider;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\Auth;
9+
10+
class ConfirmablePasswordController extends Controller
11+
{
12+
/**
13+
* Show the confirm password view.
14+
*
15+
* @param \Illuminate\Http\Request $request
16+
* @return \Illuminate\View\View
17+
*/
18+
public function show(Request $request)
19+
{
20+
return view('auth.confirm-password');
21+
}
22+
23+
/**
24+
* Confirm the user's password.
25+
*
26+
* @param \Illuminate\Http\Request $request
27+
* @return \Illuminate\Http\RedirectResponse
28+
*/
29+
public function store(Request $request)
30+
{
31+
if (! Auth::validate([
32+
'email' => $request->user()->email,
33+
'password' => $request->password,
34+
])) {
35+
return back()->withErrors([
36+
'password' => __('auth.password'),
37+
]);
38+
}
39+
40+
$request->session()->put('auth.password_confirmed_at', time());
41+
42+
return redirect()->intended(RouteServiceProvider::HOME);
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Providers\RouteServiceProvider;
7+
use Illuminate\Http\Request;
8+
9+
class EmailVerificationNotificationController extends Controller
10+
{
11+
/**
12+
* Send a new email verification notification.
13+
*
14+
* @param \Illuminate\Http\Request $request
15+
* @return \Illuminate\Http\Response
16+
*/
17+
public function store(Request $request)
18+
{
19+
if ($request->user()->hasVerifiedEmail()) {
20+
return redirect()->intended(RouteServiceProvider::HOME);
21+
}
22+
23+
$request->user()->sendEmailVerificationNotification();
24+
25+
return back()->with('status', 'verification-link-sent');
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Providers\RouteServiceProvider;
7+
use Illuminate\Http\Request;
8+
9+
class EmailVerificationPromptController extends Controller
10+
{
11+
/**
12+
* Display the email verification prompt.
13+
*
14+
* @param \Illuminate\Http\Request $request
15+
* @return mixed
16+
*/
17+
public function __invoke(Request $request)
18+
{
19+
return $request->user()->hasVerifiedEmail()
20+
? redirect()->intended(RouteServiceProvider::HOME)
21+
: view('auth.verify-email');
22+
}
23+
}

0 commit comments

Comments
 (0)