Omega P Omega P - 4 months ago 6
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!


See the documentation on controllers.

Your controller code should look like this:

public function add($post, $comment){
    echo $post;
    echo $comment;