Laravel function call question

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Laravel function call question

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Laravel function call question

Post 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.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: Laravel function call question

Post 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)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Laravel function call question

Post 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.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: Laravel function call question

Post by gautamz07 »

Thanks celauran :)
Post Reply