public function save() { $r = Input::all(); //$r['date'] = sqldate($r['date']); //$r['amount'] = unformat_money($r['amount']); $r['user_id'] = Auth::user()->id; //$r['status'] = (User::permitted( 'role.admin') === true) ? 1 : 0; //Insert into database $created = Vendor::create($r); $data['status'] = 'success'; $data['message'] = 'Record saved successfully!'; return Response::json($data); }
public function create() { if (!empty($_POST['vendid']) && !empty($_POST['compname']) && !empty($_POST['phone']) && !empty($_POST['email'])) { if (Vendor::find_by_vendid($_POST['vendid'])) { return 4; //Cannot enter Duplicated vendor ID exit; } $newVendor = new Vendor(); if (isset($_FILES['fupload']) && $_FILES['fupload']['error'] == 0) { //if file upload is set move_uploaded_file($_FILES['fupload']['tmp_name'], "public/uploads/" . basename($_FILES['fupload']['name'])); $image = new Imageresize(); // an instance of image resize object $image->load("public/uploads/" . basename($_FILES['fupload']['name'])); //$image->image =; $image->resize(400, 400); $image->save("public/uploads/" . basename($_FILES['fupload']['name'])); //this section is needed to get the extension for image type in renaming the image if ($_FILES['fupload']['type'] == "image/gif") { $ext = ".gif"; } if ($_FILES['fupload']['type'] == "image/png") { $ext = ".png"; } if ($_FILES['fupload']['type'] == "image/jpeg") { $ext = ".jpeg"; } if ($_FILES['fupload']['type'] == "image/pjpeg") { $ext = ".jpeg"; } if ($_FILES['fupload']['type'] == "image/gif") { $ext = ".gif"; } if ($_FILES['fupload']['type'] == "image/jpg") { $ext = ".jpg"; } $new_name = uniqid() . "_" . time() . $ext; //new name for the image rename("public/uploads/" . basename($_FILES['fupload']['name']), "public/uploads/" . $new_name); $photo = $new_name; $newVendor->img_url = $photo; } else { //$applicant->img_url = $_POST['imgvalue']; } $newVendor->vend_id = $_POST['vendid']; $newVendor->vend_name = $_POST['compname']; $newVendor->vend_contact = $_POST['contact']; $newVendor->vend_address = $_POST['address']; $newVendor->vend_city = $_POST['city']; $newVendor->vend_state = $_POST['state']; $newVendor->vend_country = $_POST['country']; $newVendor->vend_phone = $_POST['phone']; $newVendor->vend_email = $_POST['email']; $newVendor->vend_website = $_POST['website']; $newVendor->vend_accno = $_POST['accno']; $newVendor->vend_datecreated = date("Y-m-d H:i:s"); if ($newVendor->create()) { return 1; //returns 1 on success } else { return 2; // returns 2 on insert error } } else { return 3; //returns 3 if requiered input field is not supplied } }
<?php Route::get('vendor/add', function () { //view return View::make('add'); }); Route::post('vendor/add', function () { Vendor::create(Input::all()); var_dump('vendor is added....'); }); Route::get('vendor/{id}', function ($id) { $vendor = Vendor::find($id); return View::make('vendor', compact('vendor')); });