php - Can't upload photo in Laravel 4 -


I am trying to add some products to my database and I have to upload the photo of this product. I have created a controller, but see but when I click on Create, I have no errors, but I do not even have a picture. I just want to upload JPG, JPG, GIF, PNG files. How can I do this? Here is my code:

Controller:

  Public work postAddProduct () {$ destinationPath = ''; $ Filename = ''; $ NewId = Products :: Maximum ('ID') + 1; $ Validator = validator :: Create (Input :: All (), array ('name' = & gt; 'required', 'description' = & gt; 'required', 'partner_link' = & gt; 'required', 'Image' = & gt; 'required')); If (input :: isfile ('image')) {$ file = input :: file ('image'); $ DestinationPath = public_path () '/ Upload / product /'; $ Filename = $ newId '.' $ File- & gt; GetClientOriginalExtension (); $ UploadSuccess = $ file- & gt; Move ($ destination path, $ filename); } If ($ valid-> pass ()) {$ product = new product; $ Product- & gt; Name = input :: get ('name'); $ Product- & gt; Description = input :: get ('description'); $ Product- & gt; Category_id = input :: mill ('category'); $ Product- & gt; Partner_link = input :: find ('partner_link'); $ Product- & gt; Photo = $ filename; $ Product- & gt; Save (); Return Redirects :: Back (); } Other {Return Redirect :: Back () - & gt; Along with partners ($ verifier) ​​- & gt; WithInput (); }}  

see:

  {{form :: open (array ('url' => 'user / admin / products / addd' , 'Class' = & gt; 'col-md-4', 'style' => 'float: none; margin: 0 auto', 'id' => 'register-form')}} } & Lt; H2 square = "form-signin-title" & gt; Add Products & lt; / H2 & gt; {{Form: text ('name', empty, array ('class' => form-control' 'placeholder' '& gt;' name '))}} {{form :: text (' description ('Class' = & gt;' form-control ',' placeholder '= & gt;' description '))}} {{form :: text (' partner_link ', null, array (' class '= & Gt;' form-control ',' placeholder '= & gt;' partner link '))}} {{form :: label (' category ',' category: ', array (' class' = & gt; ; 'Field-name'))}} & lt; Select name = "category" & gt; & Lt ;? Php $ i = 0; ? & Gt; @foreach (categories as category $) & lt; Optgroup label = "{{$ class ['name']}}" & gt; $ Foreach ($ category ['subcategories'] $ as sub) & lt; Option value = "{{$ sub- & gt; ID}}" {{$ sub- & gt; Name}} & lt; / Option & gt; @earnchach & lt; / Optgroup & gt; @earnchach & lt; / Select & gt; & Lt; Div class = "clearfix" & gt; & Lt; / Div & gt; {{Form :: file ('image', array ('style' => margin-bottom: 10px '))}} {{form: submit (' save ', array (' class' = & gt; 'BTN BTN-Large BTN-Primary BTN-Block')}} {{Form :: Closed ()}}  

You have the form 'file' set to 'true':

  {{form :: open (array ('url' = & gt; 'Foo / bar', 'file' => true))}}  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -