Reputation: 35
I'm writing a code in Laravel. When I try to make a post with a file in the form, it will throw the following exception:
Got error 'PHP message: PHP Fatal error: Uncaught ErrorException: include(/var/www/vhosts/web2/httpdocs/vendor/composer/../../app/Exceptions/Handler.php): failed to open stream: No such file or directory in /var/www/vhosts/web2/httpdocs/vendor/composer/ClassLoader.php:444\nStack trace:\n#0
. . .n#5 /var/www/vhosts/web2/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(803): ReflectionClass->__construct('App\...', referer: (hidden)
add.blade.php:
@include('flash::message')
<form class="form-horizontal" enctype="multipart/form-data" action="{{action('SheetController@add')}}" method="post">
@csrf
<div class="form-group">
<label class="col-md-4 control-label" for="icao">ICAO</label>
<div class="form-group col-md-4">
<input placeholder="i.e. SAAC" class="form-control input-md" id="icao" name="icao" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="fir">FIR</label>
<div class="col-md-4">
<select id="fir" name="fir" class="form-control input-md" required>
<option value="SAEF">Ezeiza</option>
<option value="SACF">Córdoba</option>
<option value="SAMF">Mendoza</option>
<option value="SAVF">Comodoro Rivadavia</option>
<option value="SARR">Resistencia</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="version">Version</label>
<div class="form-group col-md-4">
<input placeholder="i.e. 1.2" class="form-control input-md" id="version" name="version" type="text" required />
</div>
</div>
<!-- File input-->
<div class="form-group">
<label class="col-md-4 control-label" for="sheetfile">Archivo</label>
<div class="col-md-4">
<input id="sheetfile" name="sheetfile" class="form-control input-md" required type="file">
</div>
</div>
<hr style="margin-bottom:20px;">
<div class="form-group">
<div class="btn-group">
<button type="submit" class="btn btn-success">Add</button>
<input type="reset" class="btn btn-warning" value="Reset" />
</div>
</div>
</form>
SheetController.php:
public function add(Request $request)
{
if(!empty($request->all()))
{
$sheet = new Sheet();
$sheet->icao = $request->icao;
$sheet->fir = $request->fir;
$sheet->version = $request->version;
$newName = $sheet->icao.'_v'.$sheet->version.'.pdf';
if($request->file('sheetfile')->getClientOriginalExtension() != 'pdf')
{
flash()->error('File not allowed')->important();
}
else if($request->imagen->storeAs('ATC/Sheets', $newName, 'files'))
{
if($sheet->save()) flash()->success('Sheet added')->important();
else flash()->error($sheet->errors()->first())->important();
}
else flash()->error('The file could not be uploaded.')->important();
}
return redirect()->action('SheetController@list');
}
I have already tried composer update
and composer dump-autoload
Any ideas?
Upvotes: 3
Views: 17219
Reputation: 658
I fixed using this artisan commands
php artisan cache:clear
php artisan config:clear
Upvotes: 1
Reputation: 2034
If the composer dump-autoload won't work for you, then the error tells you that a directory is missing in my case, there was no migrations folder inside the database directory.
Solution: Create the migrations folder inside the database directory. You can do this using your IDE, or Windows's File Explorer. If your using Git Bash, cd to your project's database folder then do mkdir migrations to create the missing migrations directory.
Upvotes: 0