Ce este un Resource Controller in Laravel?

Stefanescu Mihai 2 years ago iNoob

In acest articol vreau sa povestesc putin despre controllerele de tip resourse din laravel. 

Un controller de tip resourse este de fapt un controller care implementeaza toate metodele necesare unui CRUD (create, read, update, delete) pe o anumita resursa.

Puteti face un astfel de controller folosind comanda de artisan

php artisan make:controller ArticleController --resource

Aceasta comanda va va face un fisier nou, ArticleController, in folder-ul de cotnrollere cu urmatoarele metode definite: index, show, create, store, edit, update, destroy. 

Atentie, artisan-ul va va face numai un `schelet`, metodele nu vor fi implementate, asta este treaba voastra.

Acum ca am discutat despre controller, hai sa discutam despre rute. 
Putem creea rute pentru toate aceste metode cu o singura linie in fisierul routes/web.php

Route::resource('articles', 'ArticleController');

Aceasta linie de fapt va defini urmatoarele rute:

GET    /articles            ArticleController@index
GET    /articles/create     ArticleController@create
POST   /articles            ArticleController@store
GET    /articles/{id}       ArticleController@show
GET    /articles/{id}/edit  ArticleController@edit
PUT    /articles/{id}       ArticleController@update
DELETE /articles/{id}       ArticleController@destory

De asemenea, putem specifica exact ce rute ne sunt necesare folosind:

Route::resource('articles', 'ArticleController')->only(['index', 'show']);

sau pentru a exclude anumite rute

Route::resource('articles', 'ArticleController')->except(['create', 'store', 'update', 'destroy']);

Sper ca acest articol v-a fost util!

Programator de ~8 ani, am lucrat la proiecte din mai multe industrstrii, de la eCommerce la telecomunicatii la automatizari. In acest timp am folosi diferite tehnologii, de la PHP, MySQL, PostgreSql, RabbitMq, Redis, Memcached si altele.

Get in touch
Pentru nelamuriri, dubii, comentarii si chestii de pe suflet ne putem auzi pe Discord, Reddit sau poti deschide o discutie noua pe forum

Neck pain relief # 5 months ago Thanks a lot for sharing this with all people you really recognise what you are speaking approximately! Bookmarked. Please also talk over with my website =). We will have a link trade contract between us
hair growth medicine # 5 months ago Currently it appears like BlogEngine is the preferred blogging platform available right now. (from what I've read) Is that what you are using on your blog?
Rlkrln # 1 month ago buy generic tricor over the counter <a href="https://fenoficor.com/">order tricor 200mg generic</a> tricor 200mg pills
pharmacie vendant du acyclovir # 1 month ago I think everything posted made a great deal of sense. But, consider this, suppose you wrote a catchier title? I am not saying your content is not good., but what if you added a headline to maybe grab people's attention? I mean Ce este un Resource Controller in Laravel? - Invata-Programare is kinda vanilla. You could look at Yahoo's front page and watch how they create post headlines to get viewers to click. You might try adding a video or a related pic or two to grab people excited about what you've written. Just my opinion, it might make your blog a little livelier.
Puymcv # 1 month ago buy zaditor 1 mg online <a href="https://geozipin.shop/">order sinequan online cheap</a> tofranil 75mg brand
Avbugg # 1 month ago buy precose generic <a href="https://dipyxcin.com/">griseofulvin 250mg sale</a> buy fulvicin 250 mg online cheap
Lvudhr # 1 month ago how to buy mintop <a href="https://aminirin.com/">brand mintop</a> new ed drugs
Bzawne # 4 weeks ago aspirin 75mg brand <a href="https://imitonin.com/">imiquimod order online</a> purchase zovirax online
Mionsa # 4 weeks ago buy dipyridamole without a prescription <a href="https://plenpid.com/">order plendil sale</a> how to buy pravastatin
Jwtrfn # 3 weeks ago florinef 100mcg brand <a href="https://pravinef.shop/">florinef over the counter</a> loperamide 2 mg for sale
Qxenoe # 3 weeks ago dydrogesterone online <a href="https://janozin.shop/">forxiga for sale</a> where can i buy empagliflozin
Yufloi # 3 weeks ago cheap prasugrel 10mg <a href="https://detorbic.com/">tolterodine 2mg over the counter</a> detrol 2mg without prescription
Hzzvtj # 3 weeks ago order etodolac without prescription <a href="https://colotazol.com/">mebeverine 135mg cheap</a> order generic pletal 100 mg
Klcagc # 2 weeks ago where to buy ferrous without a prescription <a href="https://detorbic.shop/">brand ascorbic acid 500mg</a> betapace 40mg drug
Kkrksp # 2 weeks ago pyridostigmine price <a href="https://aelimax.com/">rizatriptan pills</a> purchase rizatriptan online cheap
Lhorqh # 2 weeks ago vasotec over the counter <a href="https://casosin.shop/">doxazosin 1mg tablet</a> purchase duphalac bottless
Uwdnmd # 1 week ago buy latanoprost generic <a href="https://aexeloda.shop/">rivastigmine where to buy</a> order rivastigmine 3mg online cheap
Imsixu # 1 week ago buy betahistine sale <a href="https://benedolac.com/">probenecid 500 mg usa</a> order probalan sale
lithonate con o sin receta en España # 1 week ago Whoa! This blog looks exactly like my old one! It's on a completely different subject but it has pretty much the same page layout and design. Wonderful choice of colors!
?waar tadliq kopen # 1 week ago I think the admin of this site is genuinely working hard in favor of his site, for the reason that here every material is quality based information.
Gutbpp # 1 week ago micardis for sale <a href="https://molnenil.shop/">where can i buy molnunat</a> purchase molnupiravir without prescription
Rvilqm # 6 days ago cenforce usa <a href="https://enapocen.shop/">naprosyn price</a> aralen uk
Jraczo # 3 hours ago generic atorvastatin 10mg <a href="https://liptamol.com/">atorvastatin 10mg cheap</a> cost norvasc
Club-ul este dedicat membrilor si ofera access la mai multe zone ale website-ului.
Login Register

🔖 Bookmarks ➕
✨ Pentru a sustine aceasta comunitate am sa te rog sa te autentifici sau sa te inregistrezi!

🌪️ Discord ➕
Back to top
Folosim cookie-uri pentru a oferi functionalitatile critice ale aplicatiei Invata-Programare. Folosim cookie-uri si pentru a analiza traficul, pentru care e nevoie de consimtamantul dvs. explicit.