POST API

Save data in the database using the POST Method.

First of all Change the 


Now Create a Post Method in Controller.

function post(Request $req)
    {
        $clientmodel = new ClientModel;
        $clientmodel->name=$req->name;
        $clientmodel->email=$req->email;
        $result=$clientmodel->save();
        if($result)
        {
            return ["Result"=>"Data Post Successfully"];
        }
        else
        {
            return ["Result"=>"Data Post Failed"];
        }

    }

Note: Write in ClientModel 

public $timestamps=false;


Now create the Route

Route::post("adds", [DBController::class, 'post']);

Output:



Comments

Popular posts from this blog

Get API with Parameter

get data with API