How to retrieve data using two dropdown with button in django - django-models

I am Neeraj. i want retrieve data using two dropdown with find button from database that i am created using django model.py
home.html
<form class="flormo">
<div class="row no-gutters">
<div class="form-group col-lg-5 col-md-4">
<select class="form-control" id="vendor_type">
<option value="">Select vendor type</option>
<option value="Photographer">Photographer</option>
<option value="others">others</option>
<option value="Makeup Artist">Makeup Artist</option>
<option value="Marriage Banquet Hall">Marriage Banquet Hall</option>
</select>
</div>
<div class="form-group col-lg-4 col-md-4">
<select class="form-control" id="cityy">
<option value="">Select City</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Delhi">Delhi</option>
</select>
</div>
<div class="form-group col-lg-3 col-md-4">
<button class="fillobtn" type="button" onclick="searchVendor()">
Find Now
</button>
</div>
</div>
</form>
Model.py
# vendor model details
class v_type(models.Model):
name = models.CharField(max_length=100, default=False)
def __str__(self):
return self.name
class v_city(models.Model):
name = models.CharField(max_length=100, default=False)
def __str__(self):
return self.name
class rank_img(models.Model):
image = models.ImageField(upload_to='vendor/rank_img')
name = models.CharField(max_length=100, default=False)
def __str__(self):
return self.name
class vendor_details(models.Model):
V_type = models.ForeignKey(v_type, null=False, on_delete=models.DO_NOTHING)
V_city = models.ForeignKey(v_city, null=False, on_delete=models.DO_NOTHING)
Profile_image = models.ImageField(upload_to='vendor/profile_imgs')
Rank_img = models.ForeignKey(rank_img, null=True, on_delete=models.DO_NOTHING)
Title = models.CharField(max_length=100, null=False)
Short_title = models.CharField(max_length=100, null=True)
User_upto = models.CharField(max_length=100)
Location = models.CharField(max_length=200, null=False)
Latitude = models.IntegerField()
Longitude = models.IntegerField()
Star = models.CharField(max_length=5)
All_Price_list = RichTextField()
First_service_name = models.CharField(max_length=200)
First_service_Price = models.CharField(max_length=200, default='')
Second_service_name = models.CharField(max_length=200)
Second_service_Price = models.CharField(max_length=200, default='')
slug = models.SlugField(default='', max_length=500, null=True, blank=True)
publish_date = models.DateTimeField(auto_now_add=True, editable=False)
def admin_photo(self):
return mark_safe('<img src="{}" width="100" />'.format(self.Profile_image.url))
admin_photo.short_description = 'Image'
admin_photo.allow_tags = True
def __str__(self):
return self.Title
def get_absolute_url(self):
from django.urls import reverse
return reverse("vendor_detail", kwargs={'slug': self.slug})
class Meta:
db_table = "app_vendor_details"
def create_slug(instance, new_slug=None):
slug = slugify(instance.Title)
if new_slug is not None:
slug = new_slug
qs = vendor_details.objects.filter(slug=slug).order_by('-id')
exists = qs.exists()
if exists:
new_slug = "%s-%s" % (slug, qs.first().id)
return create_slug(instance, new_slug=new_slug)
return slug
def pre_save_post_receiver(sender, instance, *args, **kwargs):
if not instance.slug:
instance.slug = create_slug(instance)
pre_save.connect(pre_save_post_receiver, vendor_details)
class v_Image(models.Model):
Vendor_details = models.ForeignKey(vendor_details, on_delete=models.CASCADE)
Vendor_Image = models.ImageField(upload_to='vendor/vendor_Image')
def admin_photo(self):
return mark_safe('<img src="{}" width="100" />'.format(self.Vendor_Image.url))
admin_photo.short_description = 'Image'
admin_photo.allow_tags = True
class v_desc(models.Model):
vendor_details = models.ForeignKey(vendor_details, on_delete=models.CASCADE)
V_heading = models.CharField(max_length=100, null=False)
V_descrption = RichTextField()
def __str__(self):
return self.V_heading
Admin.py
from django.contrib import admin
from .models import *
class Product_Images(admin.TabularInline):
model = Product_Image
readonly_fields = ('admin_photo',)
class Product_Admin(admin.ModelAdmin):
inlines = (Product_Images,)
list_display = ('admin_photo','Title','Categories','SKU','Real_Price','Sale_Price','section','featured_image')
list_editable = ('Categories','section')
list_filter = ('Categories','section')
readonly_fields = ('admin_photo',)
list_display_links = ['Title','Sale_Price']
#for vendor
class Vendor_Images(admin.TabularInline):
model = v_Image
readonly_fields = ('admin_photo',)
class Vendor_desc(admin.TabularInline):
model = v_desc
class Vendor_Admin(admin.ModelAdmin):
inlines = (Vendor_Images,Vendor_desc)
list_display = ('admin_photo', 'Title', 'V_type', 'V_city', 'Star', 'slug', 'publish_date')
list_editable = ('Star',)
list_filter = ('V_type', 'V_city')
readonly_fields = ('admin_photo',)
list_display_links = ['Title',]
search_fields = ['Title','V_type']
# Register your models here.
admin.site.register(top_slider)
admin.site.register(Popular_Venue)
admin.site.register(Sub_Banner)
admin.site.register(Popular_Search)
admin.site.register(Top_Categories)
admin.site.register(Main_category)
admin.site.register(Category)
admin.site.register(Sub_Category)
admin.site.register(Product,Product_Admin)
admin.site.register(Product_Image)
admin.site.register(Section)
#admin.site.register(v_desc)
admin.site.register(vendor_details,Vendor_Admin)
admin.site.register(v_Image)
admin.site.register(v_city)
admin.site.register(v_type)
admin.site.register(rank_img)
urls.py
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from .import views
urlpatterns = [
path('admin/', admin.site.urls),
path('base/',views.BASE, name='base.html'),
path('404',views.Error404,name='404'),
path('', views.HOME, name='home.html'),
path('product/<slug:slug>',views.PRODUCT_DETAIL,name='product_detail'),
#account
path('my-account', views.MY_ACCOUNT,name='my-account'),
#vendor
path('vendor/<slug:slug>', views.V_DETAILS,name='vendor_detail')
]+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
views.py
from django.shortcuts import redirect, render
from app.models import top_slider, Popular_Venue, Sub_Banner, Popular_Search, Top_Categories, Product, vendor_details
def BASE(request):
return render(request, 'base.html')
def HOME(request):
top_sliders = top_slider.objects.all().order_by('-id')
Popular_Venues = Popular_Venue.objects.all().order_by('-id')
Sub_Banners = Sub_Banner.objects.all().order_by('-id')
Popular_Searches = Popular_Search.objects.all().order_by('-id')
Top_Category = Top_Categories.objects.all().order_by('-id')
product = Product.objects.filter(section__name="dot")
context = {
'top_sliders': top_sliders,
'Popular_Venues': Popular_Venues,
'Sub_Banners': Sub_Banners,
'Popular_Searches': Popular_Searches,
'Top_Category': Top_Category,
'product': product
}
return render(request, 'Main/home.html', context)
def Error404(request):
return render(request, 'errors/404.html')
def PRODUCT_DETAIL(request,slug):
return render(request, 'product/product_detail.html')
def MY_ACCOUNT(request):
return render(request, 'account/my-account.html')
def V_DETAILS(request,slug):
vendor = vendor_details.objects.filter(slug = slug)
context = {
'vendor':vendor,
}
return render(request, 'v_items/vendor_detail.html',context)
After filter dropdown & click on findnow button redirect on this page { vendor.py}
vendor.py
{% extends 'base.html' %}
{% block content %}
<!-- Bread Crumb STRAT -->
<div class="banner inner-banner1 toper1">
<div class="container">
<section class="banner-detail center-xs">
<h1 class="banner-title">Photographer</h1>
<div class="bread-crumb right-side float-none-xs">
<ul>
<li>Home/</li>
</ul>
</div>
</section>
</div>
</div>
<!-- Bread Crumb END -->
<!-- CONTAIN START ptb-95-->
<section class="ptb-70">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="filpric">
<div class="price-range mb-30">
<div class="inner-title">Price range</div>
<input class="price-txt" type="text" id="amount">
<div id="slider-range"></div>
</div>
</div>
</div>
<div class="short-by float-right-sm">
<span>Sort By :</span>
<div class="select-item select-dropdown">
<fieldset>
<select name="speed" id="sp" onchange="selPrice('Photographer','Delhi','')">
<option value="">Select Rating</option>
<option value="1">Rating(low>high)</option>
<option value="0">Rating(high > low)</option>
</select>
</fieldset>
</div>
</div>
<div class="col-md-4">
<div class="short-by ">
<span>Vendor :</span>
<div class="select-item select-dropdown">
<fieldset>
<select name="speed" id="sv" onchange="selVendor('Photographer','Delhi','')">
<option value="" selected="selected">Select Vendor</option>
<option value="Photographer">Photographer</option>
<option value="others">others</option>
<option value="Makeup Artist">Makeup Artist</option>
<option value="Marriage Banquet Hall">Marriage Banquet Hall</option>
</select>
</fieldset>
</div>
</div>
</div>
</div>
<hr class="liko">
<!-- vendor list-->
<div class="row">
<div class="col-lg-4 col-md-4">
<div class="vankibox">
<a href="{{i.get_absolute_url}}">
<div class="vanki_img">
<img src="admin.cpanel/prod_image/20220723114525.jpg">
<img class="vatag" src="images/handpicked.png">
</div>
<div class="vankjdes">
<div class="vantitl">
<h4 class="">
seth </h4>
<p>
<i class="fa fa-star"></i> 4 <span>(5 review)</span>
</p>
</div>
<div class="">
<p class="vanadd">
<i class="fa fa-map-marker"></i> <span>New Delhi</span>
</p>
<p class="vanpric">
<span>
<small>ff</small>
<br>
<i class="fa fa-inr"></i>8000 </span>
<span>
<small>ff</small>
<br>
<i class="fa fa-inr"></i>6000 </span>
</p>
</div>
</div>
</a>
</div>
</div>
</div>
</div>
</section>
{% endblock %}
so please help me how i can code this dropdown using my store value with vendor type {v_type} & vendor city {v_city} in Vendor details model.

Related

ModelForm not saving data into database

Here is the Model
class Profile(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
profile_pic = ResizedImageField(size=[294, 313], crop=['middle', 'center'], upload_to='profilePicture', null=True, blank=True)
bio = models.CharField(max_length=100, blank=True)
address = models.CharField(max_length=500, blank=True)
mobile_number = models.CharField(max_length=15, blank=True)
def __str__(self):
return str(self.user.first_name)
I have used post_save signal while creating User.
Here is ModelForm
class UserInfo(forms.ModelForm):
class Meta:
model = Profile
fields = ('profile_pic', 'bio', 'address', 'mobile_number')
Here is views.py file:
def updatepersonalinfo(request, slug):
user = get_object_or_404(User, slug=slug)
if request.method == 'POST':
form = UserInfo(request.POST or None, request.FILES or None,instance=user)
if form.is_valid():
form.save()
else:
form = UserInfo(instance=user)
context = {
'form': form,
}
return render (request, 'generaluser/updateinfo.html', context)
And this is form in template:
<form method="POST" enctype="multipart/form-data" class="form-contact contact_form">
{% csrf_token %}
<div class="row w-100 ">
<div class="row d-flex justify-content-center">
<div class="col-lg-12">
<div class="section_title text-center mb-55">
<h3><span>Personal Information Update</span></h3>
</div>
</div>
</div>
<div class="col-lg-12 col-sm-12">
<label for="">About you</label>
<div class="form-group">
{{ form.bio }}
</div>
</div>
<div class="col-lg-12 col-sm-12">
<label for="">Your Picture</label>
<div class="form-group">
{{ form.profile_pic }}
</div>
</div>
<div class="col-lg-12 col-sm-12">
<label for="org_name">Contact Number</label>
<div class="form-group">
{{ form.mobile_number }}
</div>
</div>
<div class="col-lg-12 col-sm-12">
<label for=""> Your Present Address</label>
<div class="form-group">
{{form.address}}
</div>
</div>
{{ form.errors }}
<div class="col-lg-12 col-sm-12">
<button type="submit" class="button button-contactForm boxed-btn"> submit </button>
</div>
</div>
</form>
After submitting the form, It doesn't show any error. form.is_valid() function is also pass through. But The data is not saving into the database.
I also tried commit=False before saving. But that's not working at all.
It was a silly problem in my views.py file.
My model was:
class Profile(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
profile_pic = ResizedImageField(size=[294, 313], crop=['middle', 'center'], upload_to='profilePicture', null=True, blank=True)
bio = models.CharField(max_length=100, blank=True)
address = models.CharField(max_length=500, blank=True)
mobile_number = models.CharField(max_length=15, blank=True)
def __str__(self):
return str(self.user.first_name)
So in view while creating the form it should be profiles instance. But I, unfortunately, used the user instance.
Here is the correct view:
def updatepersonalinfo(request, slug):
usr = get_object_or_404(User, slug=slug)
profile = get_object_or_404(Profile, user=usr)
if request.method == 'POST':
form = UserInfo(request.POST or None, request.FILES or None, instance=profile)
if form.is_valid():
f = form.save(commit=False)
f.save()
return redirect('App_Account:profile', slug)
else:
form = UserInfo(instance=profile)
context = {
'form': form,
}
return render (request, 'generaluser/updateinfo.html', context)
I hope this would be helping those who do silly mistakes like me. Thank you.

Getting null value in HttpPostedFileBase in Asp.Net MVC

I am trying to save image in asp.net mvc but everytime I pass the value I am getting null value in httppostedfilebase parameter in controller in post method. How am I supposed to solve this? I have searched for the answer but non of the answer on internet were helpful.
My Controller Code:
[HttpPost]
public ActionResult Products(ItemDTO itemDTO,HttpPostedFileBase Picture1)
{
itemDTO.OrderItems = null;
var folder = this.Server.MapPath("~/Images/");
string newGuid = Guid.NewGuid().ToString();
string pathToCreate = Path.Combine(folder);
if (!System.IO.Directory.Exists(pathToCreate))
{
System.IO.Directory.CreateDirectory(System.IO.Path.Combine(folder));
}
//var fileName = pathToCreate + "//" + System.IO.Path.GetFileName(Picture1File.FileName);
var imageName = newGuid + System.IO.Path.GetExtension(System.IO.Path.GetFileName(Picture1.FileName));
var fileName = pathToCreate + imageName;
Picture1.SaveAs(fileName);
//itemDTO.imageName = imageName;
//....and update the database itemDTO
try
{
if (itemDTO.ItemId == 0)
{
List<ItemDTO> items = new List<ItemDTO>();
//Dictionary<string, string> postParams = new Dictionary<string, string>();
IRestResponse response = APIHelper.InvokePOSTMethod(Constants.CreateItem, itemDTO);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
items = new JavaScriptSerializer().Deserialize<List<ItemDTO>>(response.Content);
}
//ViewBag.Error = "Data save successsful!";
else
ViewBag.Error = response.Content;
}
else
{
//List<ItemDTO> item = new List<ItemDTO>();
//Dictionary<string, string> dict = new Dictionary<string, string>();
//dict.Add("id", itemDTO.ToString());
IRestResponse response = APIHelper.InvokePOSTMethod(Constants.UpdateItem, itemDTO);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
List<ItemDTO> item = new List<ItemDTO>();
item = new JavaScriptSerializer().Deserialize<List<ItemDTO>>(response.Content);
}
//ViewBag.Error = "Data save successsful!";
else
ViewBag.Error = response.Content;
}
}
catch (Exception ex)
{
//Log.Error(ex);
return Json("false", JsonRequestBehavior.AllowGet);
}
return Json("true", JsonRequestBehavior.AllowGet);
}
My Model Class:
public class ItemDTO
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public ItemDTO()
{
this.OrderItems = new HashSet<OrderItem>();
}
public int ItemId { get; set; }
public string ItemCategory { get; set; }
public string ItemName { get; set; }
public Nullable<decimal> Price { get; set; }
public string Picture1 { get; set; }
public string Desctiption { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<OrderItem> OrderItems { get; set; }
}
My View:
<form id="AddProduct" class="needs-validation" novalidate method="post" enctype="multipart/form-data">
<div class="wrapper">
<div class="main-panel">
#Html.HiddenFor(x => x.ItemId)
<div class="content">
<div class="row" id="frmAddProduct">
<div class="info-panel">
<div id="form-mode">
</div>
#*<div id="validation-summary">Please provide values for the highlighted fields.</div>*#
</div>
<div class="col-md-3">
<div class="card">
<div class="card-header card-menu py-3">
Add Products
<div class="headerRightFeatures">
<img src="~/Content/assets/img/delete.png" alt="" id="delete">
</div>
</div>
<div class="card-body">
<div class="form-row">
<div class="col-md-12 mb-3">
<label for="ItemName">Category</label>
#Html.EditorFor(model => model.ItemCategory, new { htmlAttributes = new { #class = "form-control" } })
<div class="invalid-feedback">
Please provide a valid product name.
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-12 mb-3">
<label for="ItemName">Product Name</label>
#Html.EditorFor(model => model.ItemName, new { htmlAttributes = new { #class = "form-control" } })
<div class="invalid-feedback">
Please provide a valid product name.
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-12 mb-3">
<label for="Price">Price</label>
#Html.EditorFor(model => model.Price, new { htmlAttributes = new { #class = "form-control" } })
<div class="invalid-feedback">
Please provide a valid price.
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-12 mb-3">
#Html.LabelFor(model => model.Picture1)
<input type="file" id="Picture1" name="Picture1" />
</div>
</div>
<div class="form-row">
<div class="col-md-12 mb-3">
<label for="Price">Description</label>
#Html.EditorFor(model => model.Desctiption, new { htmlAttributes = new { #class = "form-control" } })
<div class="invalid-feedback">
Please provide a valid price.
</div>
</div>
</div>
<div class="wAuto button-wrapper fleft">
<input type="button" value="Save" class="btn btn-primary btn-sm" id="btn-submit-product" />
<input type="button" value="Cancel" class="btn btn-primary btn-sm" id="btn-cancel-product" />
</div>
</div>
</div>
</div>
</div>
<table id="productlisting" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Item Id</th>
<th>Item Category</th>
<th>Item Name</th>
<th>Picture1</th>
<th>Price</th>
<th>Description</th>
</tr>
</thead>
</table>
Use submit button instead of button
Use
<input type="submit" value="Save" class="btn btn-primary btn-sm" id="btn-submit-product" />
instead of
<input type="button" value="Save" class="btn btn-primary btn-sm" id="btn-submit-product" />
HttpPostedFileBase only get value when button type is submit
<form id="AddProduct" class="needs-validation" novalidate method="post" enctype="multipart/form-data">
<div class="wrapper">
#Html.Hidden("ItemId", 2)
<div class="main-panel">
<div class="content">
<div class="row" id="frmAddProduct">
<div class="info-panel">
<div id="form-mode">
</div>
</div>
<div class="col-md-3">
<div class="form-row">
<div class="col-md-12 mb-3">
<input type="file" id="Picture1" name="Picture1" />
</div>
</div>
<div class="wAuto button-wrapper fleft">
<input type="submit" value="Save" class="btn btn-primary btn-sm" id="btn-submit-product" />
</div>
</div>
</div>
</div>
</div>
</div>
</form>
[HttpPost]
public ActionResult Index(int ItemId, HttpPostedFileBase Picture1)
{
return View();
}

How can I filter my model instances based off of their categorical attribute, using a select option input field (selecting from a drop down menu)

I have a blog Post model, and one of its attributes is a categorical attribute (store_type). This categorical attribute contains 4 possible values: cafe, coffee house, dessert cafe, and restaurant
I want to create a filter so that I can display the posts according to the type of store associated with that post, and I want the user to be able to use a drop down menu, rather than search by character field input. Here's my model.
I have already made a filter for the title, and it works accordingly.
class Post(models.Model):
store_choices = [
('1', 'cafe'),
('2', 'dessert cafe'),
('3', 'coffee house'),
('4', 'restaurant')
]
title = models.CharField(max_length=100)
review = models.TextField(default='Paragraph 1', max_length=3000)
store_type = models.CharField(choices=store_choices, max_length=100)
In my views.py file, I created a filter class, and I passed the store_type list into context so that I could reference these values in my template.
def PostFilter(request):
qs = Post.objects.all()
store_type = [
('cafe'),
('dessert cafe'),
('coffee house'),
('restaurant')
]
title_query = request.GET.get('title')
store_type_query = request.GET.get('store_type')
if valid_query(title_query):
qs = qs.filter(title__icontains=title_query)
context = {
'queryset': qs,
'store_type': store_type
}
return render(request, 'blog/search.html', context)
Then in my html template, I try to reference these categorical values:
<div class="container py-5">
<form method="GET" action=".">
<!-- Search by title -->
<div class="form-row d-block">
<div class="form-group col">
<label for="title">Store Name</label>
<div class="input-group">
<input class="form-control py-2 border-right-0 border" type="search" name="title" placeholder="Name contains..." />
<span class="input-group-append">
<div class="input-group-text bg-transparent">
<i class="fa fa-search"></i>
</div>
</span>
</div>
</div>
<!-- Search by store type-->
<div class="row">
<div class="form-group col-6">
<div class="container mt-4 mb-4">
<label for="storetype">Store Type</label>
<select class="form-control" name="store_type">
<option selected>Choose...</option>
{% for store in store_type %}
<option value="{{ store }}"> {{ store }} </option>
{% endfor %}
</select>
</div>
Again, my filtering method seems to work fine when it comes to filtering by character field input, but I can't seem to get a working filter that uses a drop down menu (option select) method.

how to insert the current url of the page in the database

if (ModelState.IsValid)
{
ip.patientname = fc["patientname"];
ip.patientmail = fc["patientmail"];
ip.patientcountry = fc["patientcountry"];
ip.patientquery = fc["patientquery"];
ip.SecurityCode = fc["SecurityCode"];
string url = Request.Url.AbsoluteUri;
dblayer.Add_data_pharma(ip);
TempData["msg"] = "Inserted";
}
else
{
TempData["msg"] = "Not Inserted";
}
ModelState.Clear();
return Redirect(Request.UrlReferrer.PathAndQuery);
}
string url = Request.Url.AbsoluteUri;
I want to know how to insert url name in the database using Request.Url.AbsoluteUri or any method.
public void Add_data_pharma(insert_askpharma_mar212019 ip)
{
SqlCommand com = new SqlCommand("insert_askpharma", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("#pharmaid", ip.pharmaid);
com.Parameters.AddWithValue("#patientname", ip.patientname);
com.Parameters.AddWithValue("#patientmail", ip.patientmail);
com.Parameters.AddWithValue("#patientcountry", ip.patientcountry);
com.Parameters.AddWithValue("#patientquery", ip.patientquery);
com.Parameters.AddWithValue("#SecurityCode", ip.SecurityCode);
com.Parameters.AddWithValue("#urlname", string.Empty);
com.Parameters.AddWithValue("#ipaddress", string.Empty);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
I want to insewrt the current page url in the database using mvc
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-6">
<h3 style="color:#669900">Personal Information</h3>
#using (Html.BeginForm("AskOurPharmacist", "Basic", FormMethod.Post, new { #id = "kycFormTab5" }))
{
<div class="form-group">
<label for="email">Name*</label>
<input type="text" class="form-control" id="patientname" name="patientname">
</div>
<div class="form-group">
<label for="pwd">Phone*</label>
<input type="text" class="form-control" id="" name="">
</div>
<div class="form-group">
<label for="email">Email*</label>
<input type="email" class="form-control" id="patientmail" name="patientmail">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="patientcountry" name="patientcountry">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="patientquery" name="patientquery">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="SecurityCode" name="SecurityCode">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="urlname" name="urlname">
</div>
<button type="submit" class="btn btn-success">Email me When in Stock</button>
}
</div>
<div class="col-sm-6">
<div class="rbox">
<h4 class=" text-center"><strong>Why shop with Us?</strong></h4>
<ul class="list-unstyled">
<li><i class="fa fa-heart"> </i>Trusted for Quality and Price</li>
<li><i class="fa fa-heart"> </i>80-90% Savings - Lowest Prices</li>
<li><i class="fa fa-heart"> </i>Free Shipping WorldWide*</li>
<li><i class="fa fa-heart"> </i>360° Round View of Products</li>
<li><i class="fa fa-heart"> </i>No Hidden Cost</li>
<li><i class="fa fa-heart"> </i>Saving Rewards, Referral Discounts</li>
<li><i class="fa fa-heart"> </i>Quality-Assured Medications</li>
<li class="text-right">*T&C Apply</li>
</ul>
</div>
</div>
</div>
</div>
This is my view ,in one mehod i have inserted two forms in this form only i want to insert the url in the database all are in the same table
this is my database
you must have a column(if not add 1 with name url) in database let say url which also will be available(if not add a property with the name url) in Model class ip. You method dblayer.Add_data_pharma(ip) will do the rest.
ip.url = Request.Url.AbsoluteUri;

Do not update records in the database Laravel

I can not understand why, but the records in the database are not updated ... All data reaches, even after the save () method if you dump the object, then the data from the form is stored correctly, and in the database itself there is no change, besides it is not the first method updating the data, making stores with the same method and everything worked, even in this project the category editing method works. Here's the actual method:
public function UpdateCountry(Request $request)
{
$Countries = Countries::where('Id', $request->get('Id'))->first();
$Countries->Country = $request->get('Country');
$Countries->Continent = $request->get('Continent');
$Countries->Class = $request->get('Class');
$Countries->save();
return back()->with('status', 'Updated success!');
}
Model fillable:
protected $fillable = ['Id', 'Country', 'Class', 'Continent'];
Routes, which use this method:
Route::get('country/editor/edit/{Id}','AdminController#EditCountry')->name('EditCountry');
Route::post('country/editor/save','AdminController#UpdateCountry')->name('UpdateCountry');
A similar method for editing categories that works.
public function UpdateCat(Request $request) {
$data = $request->all();
$Category = Categories::find($data['id']);
$Category->Category = $data['Category'];
$Category->save();
return back()->with('status', 'Updated success');
}
View:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card card-default">
<div class="card-header">Dashboard</div>
#if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
#endif
<div class="container">
<form action="{{route('UpdateCountry')}}" method="post">
#foreach($Country as $item)
<div class="form-group">
<label for="Country">Country</label>
<input type="hidden" value="{!! $item->Id !!}" name="Id" id="Id">
<input type="text" class="form-control" id="Country" name="Country" value="{{$item->Country}}" required>
</div>
<div class="form-group">
<label for="Continent">Continent</label>
<input type="text" class="form-control" id="Continent" name="Continent" value="{{$item->Continent}}" required>
</div>
#endforeach
<input type="hidden" id="Class" name="Class" value="flag flag-default">
<button type="submit" class="btn btn-success">Save</button>
{{csrf_field()}}
</form>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
Well, I solved this question, and it turned out to be very simple. In the model it was necessary simply to indicate:
protected $primaryKey = ['Id'];

Resources