Omega P Omega P - 2 years ago 117
PHP Question

Laravel 5.1: Controller use variable from method [Get]

I have code in route.php

Route::get('website/{post}/{comment}', ['uses'=>'MainController@add']);

In file MainController:

public function add(Requests $request){
$data = $request->all();
echo $data['post'];
echo $data['comment'];

Can i do like this? If i can, help me fix it.

Thank you!

Answer Source

See the documentation on controllers.

Your controller code should look like this:

public function add($post, $comment){
    echo $post;
    echo $comment;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download