jeudi 29 novembre 2018

Save Post Data from External Server To Laravel

I want to save information posted to a callback URL to a Laravel database. I have created a controller and a route in the api.php file but the posted information is not being saved. When I create a PHP file in the public folder, the info is being saved but I want it to go through a controller. Kindly let me know what I need to do to save the info.

Route: Route::post('/receivesms', 'MessageController@stk');

Controller:

namespace App\Http\Controllers;

use App\Message;
use Illuminate\Http\Request;

class MessageController extends Controller
{
    public function stk(Request $req){

        $message = new Message();
        $message->sender = $req->input('from');
        $message->recipient = $req->input('to');
        $message->message = $req->input('message');
        $message->date_sent = $req->input('date');
        $message->message_id = $req->input('id');
        $message->link_id = $req->input('linkId');
        $message->save();

        return view('welcome');
    }
}

The posted info is as explained here. with the posted data being;

 $from = $_POST['from'];
 $to = $_POST['to'];
 $text = $_POST['text'];
 $date = $_POST['date'];
 $id = $_POST['id'];
 $linkId = $_POST['linkId']; 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire