0

Form

<form files ="true" action="{{ route('mynewproject') }}">
   <input  type="file" name="projectimage" id="projectimage">
 <button type="submit">Submit</button>
</form>

DashbordController

This is my controller to check only the input has file or not but it gives me no files:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\project;
use Input;
use Image;
use File;

class DashbordController extends Controller
{

   public function projectAdded(Request $request){
    if(Input::hasFile('projectimage')){
    return $request->projectimage;
  }else{
   return 'no file';
  }
}

2 Answers 2

2

The problem lies with your form HTML element. The attribute files isn't recognized. You're likely confusing it with the attribute you're able to pass to the Laravel Collective Form/Html package, which upon output converts adds the enctype attribute to the form opening tag.

You should change your form tag to this:

<form method="post" enctype="multipart/form-data" action="{{ route('mynewproject') }}">

Notice the enctype attribute. That should allow you to upload files.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but not solve it gives me an error that method GET,POST is not allowed
This solves it - but the next error you are getting is due to an error in your routes.
0

<?php 

public function projectAdded(Request $request){
    if($request->hasFile('projectimage')){
    return $request->projectimage;
  }else{
   return 'no file';
  }
}

?>

1 Comment

Use above code and check with $request->hasFile('projectimage')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.