This PHP code :
<?php
if(isset($_POST['uid'])) {
$uid = $_POST["uid"];
$sql = mysqli_query($dbconnect, "INSERT INTO tb_entry VALUES ('$uid')");
}
?>
How can I write this code into Laravel controller?
CodePudding user response:
it should be like this
if ($request->has('uid')) {
DB::table('tb_entry')->insert([
'uuid' => $request->uuid
]);
}
CodePudding user response:
- create a controller:
php artisan make:controller MyController
- add a method to the controller like
public function test(Request $request) {}
- rewrite your code a little bit and pasted in:
public function test(Request $request) {
if (isset($request->post('uid'))) {
$uid = $request->post('uid');
// Note: you can use laravel model instead plain mysqli query
$sql = mysqli_query($dbconnect, "INSERT INTO tb_entry VALUES ('$uid')");
}
}