Snippet
Snippet

Reputation: 1560

Passing a GET value in route

I have this following Controllers on my file

class MyController1 extends BaseController{

    public function notify($id,$message){
        //Sending a push notification
        //Google Cloud Messaging Here
        //****//
    }
}

How do i write the route to pass a value to id and message using GET?

Route::get("/sendMessage" , MyController1@notify);

the url should be something like

https://mysite.com/sendMessage?id=1&message=Hello

Also I need to call the notify method from other controllers like this. .

class MyController2 extends BaseController{

    public function something(){  
         $con = new MyController2();
         $con->notify($id,$message);

    }
}

What should I put to the notify the model?

Upvotes: 0

Views: 38

Answers (2)

xate
xate

Reputation: 6389

This is the code you need to create GET parameters in your URL:

Route::get('sendMessage/{id}/{msg}'

More information here: http://laravel.com/docs/routing#route-parameters

Greetings

Upvotes: 1

dops
dops

Reputation: 800

Laravel URL's work slightly differently to how you want it.

In Laravel as standard your URL for the above example will be

https://mysite.com/sendMessage/1/Hello 

and your route would be

Route::get("/sendMessage/{id}/{message}" , MyController1@notify);

the text in the braces {} will be the name of the parameter passed to the controller function

eg. https://mysite.com/sendMessage/1/Hello would call MyController->notify(1,'Hello');

Upvotes: 0

Related Questions