Page 1 of 1

Laravel function call question

Posted: Tue Aug 18, 2015 3:35 pm
by gautamz07
I am building a small demo ecommerce website and basiclly have managed to build a small prototype. now i have main page, Here https://github.com/gautamz07/laravel-ec ... .blade.php , On the main page there are 4 products loaded (the latest products). now when you click on the inidivisual products , it takes you to the indivisual backpages of the product (https://github.com/gautamz07/laravel-ec ... .blade.php) .


You must be wondering how does clicking on the indivisual links take you to its backpages , if you have a closer look at the code on index.blade.php the href of each a tag looks like so:

Code: Select all

<a href="store/view/{{ $product->id }}">
.

have a look at the store controller here https://github.com/gautamz07/laravel-ec ... er.php#L17

did you notice the following method:

Code: Select all

public function getView($id) {
    return View::make('store.view')->with('product' , Product::find($id));
  }
I think the view part in the controller is calling getView() in the storeController, this is amusing to me, as how does laravel or php know how to map view (in the link ) to getView($id) function ??

Thank you.

Re: Laravel function call question

Posted: Tue Aug 18, 2015 3:39 pm
by Celauran
You're using controller routing, so it's parsing the URI as /controller/action/params and prefixing the action with the HTTP verb used. Send a POST request to /store/view/123 and a different action would be triggered.

Re: Laravel function call question

Posted: Tue Aug 18, 2015 3:45 pm
by gautamz07
You're using controller routing
what do you mean by that ?

Code: Select all

Send a POST request to /store/view/123 and a different action would be triggered.
I kind of realise that :) (though don't understand it totally yet)

Re: Laravel function call question

Posted: Tue Aug 18, 2015 3:51 pm
by Celauran
gautamz07 wrote:
You're using controller routing
what do you mean by that ?
https://github.com/gautamz07/laravel-ec ... es.php#L16

That.

Re: Laravel function call question

Posted: Thu Aug 20, 2015 1:21 pm
by gautamz07
Thanks celauran :)