DEV Community

Sho Nabil
Sho Nabil

Posted on

Penjelasan terkait routing,middleware &controller

1.Routing adalah
•Menentukan jalur URL dan metode HTTP untuk merespon permintaan.
•Mengarahkan permintaan ke fungsi yang sesuai.

Route::get('/santri', function () {
    return 'Santri Koding';
});
Enter fullscreen mode Exit fullscreen mode

2.Middleware adalah
•Sebagai penengah untuk memriksa data apakah data tersebeut ada atau tidak ada
php artisan make:middleware

public function handle(Request $request, Closure $next)
{
    if($request->age < 20 ) {
        return redirect()->route('home')->with('errors', 'Umur kamu masih dibawah 20 tahun!');
    }

    return $next($request);
}
Enter fullscreen mode Exit fullscreen mode

3.Controller adalah
•digunakn untuk untuk mengambil data dan melakukan proses insert update dan delete dri database

<?php
namespace App\Http\Controllers;
class SantriController extends Controller
{
    public function index()
    {
        return "SantriKoding!";
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay