Welcome

Welcome to George's Amazing World blog. Here you will enjoy what life has to offer and relax your mind after a sweatily day of work

September 7, 2017

REST Killing Laravel



After hearing about the Laravel hype, sorry, Laravel power, I decided to join the bandwagon. Of course Site Point ranks it number and other sites will rate other frameworks highly. Get me well on this, it is not Site Point alone but many other sites and among these Value Coders does a good job in explaining why Laravel is the best framework. And oh! Coder’s Eye comes with a good graphical representation of the fact – for those who love statistics.
So I started my reading journey, I grabbed a copy Laravel 5.2 and Laravel 5.3 but running examples from 5.3 code base and off I started. It was all interesting. After understanding controllers, I made a choice – I will use Route::controller() because it looks focused so it would help me manage application resources better, but Boo!, the nice feature is deprecated 5.3 – so frustrating!
To understand my frustration well, let’s have a small recap of how Laravel MVC works. In Laravel, everything is a user accesses (via the browser client) is resource stored on the server. The client can request for the resource through a URI. The client must specify operation (Create, Update etc) it wants to carry out on the resource. Whether the client can access the resource and carry out the intended operation is controlled by the Controller and Middleware.    

The URIs are implemented as routes. So for every URI you predict your web application to have, there has to be some kind of route defined for it. So for 40 URIs, you need 40 routes defined – this is tedious, not so? This was,however, solved by introducing resource and controller routes. You could still decide to define all the 40 routes or take advanced of the these two advanced features (Route::controller() or Route::resource()) . But now you can only take advantage of Route::resource().

Controller routes would allow you to implicitly access URIs attached to the controller by defining only one route and the only requirement would be to have a method in the controller starting with one of the get or post (If you started the method name with get, it will handle only get requests and if it started with post then it will handle the post request). For example, for a route like Route::controller('test', 'CompanyController'), you could access the company resource like http://example.com/test/profile  as long as you had a method like getProfile() or postProfile() defined in Companycontroller. http://example.com/test/delete, would mean there is a method named getDelete() or postDelete() in CompanyController. This was really nice, not only for implementation but also for organization. You could write your controller in such a way that all actions/operations for a resource are in one controller and accessible through one Route!!

Do you know why I writing this in past tense? Because it was deprecated in version 5.3 so if you still need it just don’t upgrade from Laravel 5.2 but you are not alone.  And do you know why it was deprecated? Well I have not yet found out. I am still asking the fountain of knowledge, Google but from what I am seeing, it is because it was violating REST. So all we are left with are resource routes.

In its effort for to implement REST, Laravel provides for resource routes. Like Controller routes, you can access resource routes through a single Route e.g., Route::resource(‘profile’, ‘ProfileController’). Unlike controller routes (Route::controller()), resource routes (Route::resource) Laravel defines specific methods e.g., in our ProfileController you can only have the following methods: index(), create(),store(Request $request), show($id), edit($id), update(Request $request, $id), destroy($id)! So if you visit http://example.com/profile/destroy/3, the controller has enough intelligence to call destroy() method of the controller.  And if you want to have any additional method in the controller apart from those provided by Laravel, you must first define a route for it. E.g., if we wanted to have a URL like http://example.com/profile/approve, then we would have to define a method such as approval()  in our ProfileController, then we would have the following routes.
Route::get(‘profile/approvals’, ‘ProfileControler@approve’)
Route::resource(‘profile, ‘ProfileController’)

Laravel versions greater than 5.2 are moving towards RESTful CRUD applications i.e., an application’s resources can be Created, Read, Updated or Destroyed (CRUD) and these can be accessed using the defined HTTP verbs such as POST, GET, PUT etc.

Conclusion

Much as the major operations on a resource are CRUD, even the “minor operations” are necessary for the creation of a meaningful and usable application. So either ask HTTP, which informed REST, to add more verbs. Asking me to explicitly add a route like Route::get(‘profile/approvals’, ‘ProfileControler@approve’)  to my routes (because Route::resource() does not support it) makes me feel like am hacking my own system. And defining a different controller for the same resource so that I can make use of the provided CRUD methods makes me feel like I am handling a different application resource.

Let us not rush things, even the mother language of the web, HTML is still using only POST and POST methods in its forms. Or are we rushing to be the first one to implement the HTTP spec?
So please bring back our Route::Controller()!!

August 19, 2011

Amazing Selfish Interest

I am an Arsenal fun but when at time of the season some one still has the nerve to tell Arsenal fans to show Arsene respect, I wonder if he is a true Arsenal fan.

Arsenal fans have not only shown Wenger respect but have also shown interest in the alarming situation at Arsenal. They have asked the him to "Sign players", that is all!! They have even gone ahead to point out the options, is that showing disrespect Mr. David Dein?


It appears to me the fans are still behind him but the to administration are against him. Why did the board force the Nasir deal thru when Wenger did not? Why don't you Does not the board give him the money from sales to make purchases?

To it appears the board frustrates Wenger (so that he gets fed up and go) and even force him to defend their selfish decisions they make.

If the fans did not respect him they would already be shoutin "Go and leave us alone" but they don't.

Mr. David Dein would how would u reach if you bought expensive tickets for 6 years to get happiness but end up in bitterness and crying? Arsenal board please respect Arsenal fans!!

May 26, 2011

Oh Uganda, How Amazing You Are!

I have been really in deep sleep since January - we had enough peace in Uganda. But alas! I was awakened by the rising commodity prices. What a situation? The peaceful state turned nasty and whoever had a right to sleep, acquired another form right.

It kind of became illegal to walk in Uganda, but luckily I could still walk. Next time I will bring the various quotations from key public figures but now I have to watch the beautiful ugly flowers that brightened and darkened the various streets of Kampala - I had the chance to see the various forms of tear-gas - I mean all flavors, here we go http://tinyurl.com/3e6wyl9

January 26, 2011

Amazing Football

It was a disappointing evening yesterday when Man-U overturned Arsenal's hopes!

Who could believe this miraculous turn, from 2-0 to 2-3!!!!
Congs Man-U but remember the unbeaten run is only for the boys not for adults!!!

January 16, 2011

The Place that Never Was

It is now two or so many weeks away from the festive season, and everyone is doing all their best to beautify their pockets after that ugly spending - To some the spending was induced by the number of visitors going to their homes, others because their beloved girl friends or boyfriends were visiting and to the majority because  the Lord had been born!

I happen to have travelled to place whose name I was told but cannot remember but atleast I can hardly forget its citizens. It is in this place where I came to belive that law of demand, The higher the price, the lower  the demand and vice versa, has place. A few animals had been slaughtered and many were the people who wanted meet so the prices shoot up but believe none was left. Dont tell me that it was the law of Supply because it does not work either.

People bought stuff as there would never be tomorrow, I had the fear that they would starve the following month but where, they still servive! to be continued.............

December 21, 2010

Amazing Accidents

It so amazing how things happen, but accidents can really happen in different ways

For some accidents find them in their beds while sleeping and have a look at theses one who are having fun

So terrible accidents out of fun

Merry Christmas and Happy New year

It is this time of the year to say Merry Christmas and happy new year to all my esteemed readers.

Make merry but please DON'T make Mary since too much merry most of the time ends up in a new Mary. For those with happy pockets to meet the attached costs like clothing, school fees please go ahead and do both  (Make Merry and Make Mary too).

Catch you soon before the new year comes by!!!!