Skip to main content

Laravel Route : Pengertian Router Resource




bill.web.id, Router laravel adalah kode program yang di gunakan untuk mendefinisikan url pada project laravel kita. router memanfaatkan htaccess untuk membuat url project kita sangat seo friendly. berbada dengan CI, router pada laravel sangat customable, berapapun level url slash nya tidak berpengaruh dengan controller dan method yang di panggil. contoh

Route::get($uri, $callback);

$uri : di isi oleh url yang ingin kita buat

$callback : di isi oleh nama class dan atau method dari controller

Baca Juga :

tentu hal ini sangat menguntungkan bagi para pengamat seo, bahwa nama url sangat berpengaruh terhadap SEO,  seperti kita tau search engine mengidentifikasi url dari nama yang tersemat di dalam urlnya, jadi pengalamatan url yang bagus akan berdampak pada kemudahan halaman kita akan terindeks search engine.

Router sendiri memiliki banyak metode, tiap metode berasosiasi pada HTTP VERB, http verb yang di gunakan oleh laravel para router terdapat 5 yaitu.

  1. GET
  2. POST
  3. PUT
  4. PATCH
  5. DELETE

Baca Juga :

setiap metode tersebut memiliki keistimewaan sendiri2, cara penggunaanya sangat gampang. kalian tinggal mengganti method yang ada di router sesuai dengan http verb di atas. contoh

  • GET

Route::get($uri, $callback);
  • POST
Route::post($uri, $callback);


dan sebagainya.

Baca Juga :

tetapi, ada satu lagi method router yang perlu kalian ketahui yaitu method RESOURCE. method ini adalah method yang mewakili semua method2 di atas agar bisa di panggil hanya dalam satu baris. contoh

  • RESOURCE

Route::resource($uri, $callback);

router di atas, akan  menghasilkan router yang berstandard resource nya laravel atau restful, router yang di cetak akan berjumlah 7, tetapi hanya akan menggunakan 4 method yang dari 5 method yang ada, kenapa? karna PUT dan PATCH fungsinya sama, yaitu mengupdate data. berikut hasil dari method resource di atas.



tiap router di atas, akan berasosiasi ke dalam method CRUD (Creat, Read, Update, Delete)  yang terdapat pada controller yang di tuju. apabila kalian masih penasaran tentang router, kalian bisa langsung membaca dokumentas router yang ada di website resmi laravel.




Popular posts from this blog

Automatic API Documentation Swagger in Golang #GolangDev

pixabay.com In this article, I'll explain how to generate an API blueprint instantly using SwagGo in Golang. API blueprint is a document that contains a bunch of API endpoints, its slickly same as documentation but less description, it's allow another programmer to read and see all the available endpoint and try it out with sandbox feature. Swagger is one of the most used API blueprints right now, it's available in free but limited usage. if you wanna use the free credit, you need to understand YAML notation, you can read the example notation in swagger official documentation. but again, it's really hard and takes an expensive time to arranges all the notation to achieve a good API blueprint. fortunately, there are tools in Golang that allow us to generate the YAML notation and automatically generate the blueprint page with only using markup notation, and it's FREE unlimited for self-host, insane right? SwagGo tools are available here , the documentation is very cl...

Playing with Hooks in Gorm #GolangDev

Pixabay Hello everyone, I would like to share some tricks in gorm, the Idea of this tricks is to execute a command or code statement in the middle of an ORM operation, if you ever know about trigger in the query language, then hooks is just kinda like that. Hooks could execute statement in some events such as: beforeCreate, beforeUpdate, afterCreate,  and afterUpdate . those event is similar as a trigger,  when the trigger is executed in DBMS layer, hooks are executed in the application layer. In my real case, my current company has different convention of naming database column, so when I try to implement ORM, a lot of columns such as created_at, updated_at and deleted_at can't be generated automatically. also if you have a custom UUID you could pass the value UUID generator into hooks before the insert is executed. for more detail let's jump into code : # Explanation Above code containing model struct, and several methods from gorm to serve model, TableName method used to d...

Create MVC Pattern Using Echo Framework #GolangDev

pixabay.com Hi, Back again. today I am gonna share about Go Language, yes it is a new programming language that really fast growing this day, so many startup using it, especially in indonesia, there is a Gojek, Dana, Tiket and many more. Go Lang is a programming language found by google engineer, this language is a multi paradigm language, you could use it as functional programming or treat it like an OOP bases. Echo is an framework that use Golang as a main language, to use a fast and reliable backend/web apps, as you know Golang has a really fast performance than other language, one of the reason is because its compiled not interpreted, so the Echo claim that its 10x faster. insane right ? Actually I didn't test the performance yet, but yeah for newbie like me in golang its not the main thing that you must understand, so the thing that we should know is how we actually can do with Golang.  I am person with MVC bases, before jump to golang, I have experience with La...