Hi, you need to add routes file along with the blade template changes to work with Laravel. Please try below code.
{{ link_to_route('customer.update', 'Link Text', [
'id' => $id
]); }}
Route::get('/update', [
'as' => 'customer.update',
'uses' => 'CustomerController@postUpdateStud'
]);
namespace ....;
class CustomerController extends Controller {
public function postUpdateStud(){
require_once ('database.php');
$id = null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if ( null==$id ) {
header("Location: index.php");
}
if ( !empty($_POST)) {
$nameError = null;
$emailError = null;
$mobileError = null;
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$valid = true;
if (empty($name)) {
$nameError = 'Please enter Name';
$valid = false;
}
if (empty($email)) {
$emailError = 'Please enter Email Address';
$valid = false;
} else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
$emailError = 'Please enter a valid Email Address';
$valid = false;
}
if (empty($mobile)) {
$mobileError = 'Please enter Mobile Number';
$valid = false;
}
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE customers set name = ?, email = ?, mobile =? WHERE id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($name,$email,$mobile,$id));
Database::disconnect();
header("Location: index.php");
}
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM customers where id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
$name = $data['name'];
$email = $data['email'];
$mobile = $data['mobile'];
Database::disconnect();
}
}
}
Note : All the codes present in "postUpdateStud" method is just the plain PHP codes. You need to work on it to change into Laravel standard.
Follow this link :-
Introduction - Laravel - The PHP Framework For Web Artisans[
^]
I hope this will help you.