PENDAHULUAN
          Laravel menangani proses otentikasi dengan berbagai cara, seperti menggunakan Jetstream, Breeze, dan sebagainya. Namun, kedua metode otentikasi tersebut terkadang terlalu kompleks jika digunakan dalam proyek-proyek dengan ruang lingkup yang lebih kecil. Oleh karena itu, Laravel menyediakan metode otentikasi manual. Pada kesempatan ini, kita akan membahas tentang cara melakukan otentikasi manual di Laravel.
Langkah 1Â
     Persiapan Awal Pastikan Anda telah memiliki proyek Laravel yang telah dibuat sebelumnya. Jika belum, Anda dapat membuatnya dengan menggunakan perintah berikut di terminal :
composer create-project laravel/laravel nama-proyek-anda
Langkah 2Â
     Database Pastikan juga Anda telah mengatur database dan informasi koneksi database di file .env proyek Laravel Anda.
Langkah 3Â
     Tabel Pengguna (Users) Jika Anda belum memiliki tabel pengguna (users) di database, buatlah dengan menggunakan migration Laravel:
php artisan migrate
Langkah 4Â
      Pembuatan Route Selanjutnya, buatlah rute (route) untuk halaman login, registrasi, dan logout. Anda dapat menambahkan rute ini di dalam file routes/web.php :
Route::get(‘/login’, ‘AuthController@showLoginForm’)->name(‘login’);
Route::post(‘/login’, ‘AuthController@login’);
Route::post(‘/logout’, ‘AuthController@logout’)->name(‘logout’);
Route::get(‘/register’, ‘AuthController@showRegistrationForm’)->name(‘register’);
Route::post(‘/register’, ‘AuthController@register’);
Langkah 5
      Pembuatan Controller Buatlah controller yang akan mengurus logika otentikasi. Anda dapat menggunakan perintah artisan berikut :
php artisan make:controller AuthController
Setelah itu, buka file AuthController yang baru dibuat di dalam folder “app/Http/Controllers” dan implementasikan metode-metode berikut :
use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class AuthController extends Controller { Â Â Â public function showLoginForm() Â Â Â { Â Â Â Â Â Â Â return view('login'); Â Â Â } Â Â Â public function login(Request $request) Â Â Â { Â Â Â Â Â Â Â $credentials = $request->validate([ Â Â Â Â Â Â Â Â Â Â Â 'email' => 'required|email', Â Â Â Â Â Â Â Â Â Â Â 'password' => 'required', Â Â Â Â Â Â Â ]); Â Â Â Â Â Â Â if (Auth::attempt($credentials)) { Â Â Â Â Â Â Â Â Â Â Â $request->session()->regenerate(); Â Â Â Â Â Â Â Â Â Â Â return redirect()->intended('/'); Â Â Â Â Â Â Â } Â Â Â Â Â Â Â return back()->withErrors([ Â Â Â Â Â Â Â Â Â Â Â 'email' => 'Kombinasi email dan password tidak cocok.', Â Â Â Â Â Â Â ]); Â Â Â } Â Â Â public function logout(Request $request) Â Â Â { Â Â Â Â Â Â Â Auth::logout(); Â Â Â Â Â Â Â $request->session()->invalidate(); Â Â Â Â Â Â Â $request->session()->regenerateToken(); Â Â Â Â Â Â Â return redirect('/'); Â Â Â } Â Â Â public function showRegistrationForm() Â Â Â { Â Â Â Â Â Â Â return view('register'); Â Â Â } Â Â Â public function register(Request $request) Â Â Â { Â Â Â Â Â Â Â $credentials = $request->validate([ Â Â Â Â Â Â Â Â Â Â Â 'name' => 'required', Â Â Â Â Â Â Â Â Â Â Â 'email' => 'required|email|unique:users', Â Â Â Â Â Â Â Â Â Â Â 'password' => 'required|min:8|confirmed', Â Â Â Â Â Â Â ]); Â Â Â Â Â Â Â $user = User::create([ Â Â Â Â Â Â Â Â Â Â Â 'name' => $credentials['name'], Â Â Â Â Â Â Â Â Â Â Â 'email' => $credentials['email'], Â Â Â Â Â Â Â Â Â Â Â 'password' => bcrypt($credentials['password']), Â Â Â Â Â Â Â ]); Â Â Â Â Â Â Â Auth::login($user); Â Â Â Â Â Â return redirect()->intended('/'); Â Â Â } }
Langkah 6
       Pembuatan View Terakhir, buatlah tampilan (view) untuk halaman login dan registrasi. Anda dapat membuat file “login.blade.php” dan “register.blade.php” di dalam folder “resources/views”.
Berikut adalah contoh sederhana kode untuk login.blade.php :
```
<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
</head>
<body>
    <h2>Login</h2>
    @if ($errors->any())
        <div>
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
    <form method=”POST” action=”{{ url(‘/login’) }}”>
        @csrf
        <label for=”email”>Email:</label>
        <input type=”email” name=”email” required>
Â
        <label for=”password”>Password:</label>
        <input type=”password” name=”password” required>
Â
        <button type=”submit”>Login</button>
    </form>
</body>
</html>
Dan berikut adalah contoh sederhana kode untuk register.blade.php :
<!DOCTYPE html>
<html>
<head>
    <title>Register</title>
</head>
<body>
    <h2>Register</h2>
Â
    @if ($errors->any())
        <div>
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
Â
    <form method=”POST” action=”{{ url(‘/register’) }}”>
        @csrf
Â
        <label for=”name”>Name:</label>
        <input type=”text” name=”name” required>
Â
        <label for=”email”>Email:</label>
        <input type=”email” name=”email” required>
Â
        <label for=”password”>Password:</label>
        <input type=”password” name=”password” required>
Â
        <label for=”password_confirmation”>Confirm Password:</label>
        <input type=”password” name=”password_confirmation” required>
Â
        <button type=”submit”>Register</button>
    </form>
</body>
</html>
Kesimpulan
       Dengan mengikuti langkah-langkah di atas, Anda dapat membuat fitur login, registrasi, dan logout secara manual di Laravel. Pastikan Anda telah memahami kode yang ditulis dan juga melakukan penyesuaian sesuai kebutuhan proyek Anda. Selamat mencoba!
Exceptional post however I was wondering if you could write a litte more on this topic?
I’d be very thankful if you could elaborate a little bit more.
Thanks!
If you are going for best contents like me, only go
to see this website everyday because it provides feature contents, thanks
you’re in reality a good webmaster. The web site loading
speed is amazing. It seems that you are doing any unique trick.
Furthermore, The contents are masterpiece. you’ve performed a excellent process on this subject!
wonderful post, very informative. I wonder why the opposite specialists
of this sector do not realize this. You should proceed
your writing. I’m confident, you’ve a great readers’ base already!
I was wondering if you ever considered changing the page layout of your website?
Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect
with it better. Youve got an awful lot of text for only having 1 or 2
images. Maybe you could space it out better?
Hello there, I found your web site by the use of Google even as
looking for a similar subject, your website got here
up, it looks good. I’ve bookmarked it in my google bookmarks.
Hello there, just became alert to your blog through Google, and located
that it’s truly informative. I am going to watch out for brussels.
I will appreciate when you proceed this in future.
Lots of other folks can be benefited from your writing.
Cheers!
Hello! I could have sworn I’ve visited this web site before but after going through many of the posts
I realized it’s new to me. Anyways, I’m certainly happy I
discovered it and I’ll be bookmarking it and checking back often!
Hi there, I enjoy reading all of your article post.
I wanted to write a little comment to support
you.
I have read so many posts concerning the blogger lovers however this article is actually a good post, keep it
up.
Hey there! I realize this is kind of off-topic however I had to ask.
Does managing a well-established website such as yours require a massive amount
work? I’m brand new to operating a blog however
I do write in my diary every day. I’d like to start a blog so I can share my personal experience and thoughts online.
Please let me know if you have any suggestions
or tips for brand new aspiring blog owners. Appreciate it!
My relatives every time say that I am wasting my time here at web, however I know I am
getting know-how everyday by reading such good content.
I love what you guys are up too. This kind of clever work and coverage!
Keep up the great works guys I’ve included you guys to my blogroll.
Please let me know if you’re looking for a author for your blog.
You have some really great posts and I think I would be a good asset.
If you ever want to take some of the load off, I’d really like to
write some content for your blog in exchange for a link back to mine.
Please blast me an email if interested. Thank you!
Hi to all, as I am in fact keen of reading this weblog’s post
to be updated on a regular basis. It contains fastidious data.
I am genuinely delighted to glance at this web site posts which includes tons of valuable
data, thanks for providing such data.
I don’t know whether it’s just me or if everybody else experiencing
problems with your blog. It seems like some of the written text within your content
are running off the screen. Can someone else please comment and let me know if this is happening to them as well?
This might be a problem with my web browser because I’ve had this happen before.
Thanks
all the time i used to read smaller content which as well clear their motive, and that is also
happening with this post which I am reading at this
time.
Wow, awesome blog layout! How long have you been blogging for?
you made blogging look easy. The overall look of your web site is fantastic, as well as
the content!
Ridiculous quest there. What happened after? Take care!
Hmm it looks like your blog ate my first comment (it was super long) so I guess I’ll just sum it
up what I submitted and say, I’m thoroughly enjoying your blog.
I as well am an aspiring blog writer but I’m still new to the whole thing.
Do you have any suggestions for inexperienced blog writers?
I’d certainly appreciate it.
I do not know if it’s just me or if everybody else
experiencing issues with your website. It appears as if some of the written text within your posts are running off the screen. Can somebody else please comment and let
me know if this is happening to them as well?
This could be a problem with my browser because
I’ve had this happen before. Appreciate it
Hi, after reading this awesome post i am also happy to share my
know-how here with friends.
My brother suggested I might like this web site. He was totally right.
This post truly made my day. You cann’t imagine
just how much time I had spent for this information! Thanks!
I’ll right away grasp your rss feed as I can’t find your e-mail subscription hyperlink or newsletter service.
Do you have any? Kindly permit me realize so that I could subscribe.
Thanks.