What did you try? I can show you how it's done, but you don't learn anything from that!
Take a look at this article: http://www.easylaravelbook.com/blog/2015/04/08/processing-file-uploads-with-laravel-5/
Hi Awesome People
I wan to upload PDF or Doc file through form and send the same file to a mail or for now i just want to upload the file to database, i really don't know how to achieve it,
I Created a file called "view/careers/apply.blade.php" there is a form with 3 input fields, i can post the name and email to database to with the help of @tykus_ikus (he really helped me a lot) but i don't know how to upload files
<form method="POST" action="apply" class="form-horizontal custm-form" role="form">
{!! csrf_field() !!}
<div class="modal-header">
<!--<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>-->
<h4 class="modal-title">Apply Online</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label col-md-3">Name:</label>
<div class="col-md-8">
<input type="text" class="form-control" id="name" placeholder="Enter Your Name" name="name">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">E-mail:</label>
<div class="col-md-8">
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" name="resume">Attach Resume:</label>
<div class="col-md-8">
<input type="file" id="resume" placeholder="Resume" name="resume" class=""/>
<span class="required" id='spnFileError'></span>
</div>
</div>
</div>
<div class="modal-footer">
<div class="col-xs-5">
<p style="margin:0;text-align:left;color: green;display:none;" id="successMsg">Submitted Successfully!</p>
</div>
<button type="submit" id="btnUpload" class="custm-btn btn-primary" onclick="uploadFile();">Submit</button>
<button type="button" class="custm-btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
My Model IS "AvoCareer.php"
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class AvoCareer extends Model {
protected $table = "avo_career";
}
?>
My Controller is "AvoCareersController.php"
<?php
namespace App\Http\Controllers;
use View;
use App\AvoCareer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Routing\Controller as BaseController;
class AvoCareersController extends BaseController {
public function careerpage() {
return view('careers.apply');
}
public function store(Request $request)
{
$avoCareer = new AvoCareer;
$avoCareer->name = $request->name;
$avoCareer->email = $request->email;
$avoCareer->resume = $request->resume;
$avoCareer->save();
return redirect('apply');
}
}
?>
And The rought is
Route::get('apply', 'AvoCareersController@careerpage');
Route::post('apply', 'AvoCareersController@store');
Looking forward for Much needed help
Thanks
@MrRobot21 please add enctype="multipart/form-data" in form tag.
<form method="POST" action="apply" class="form-horizontal custm-form" role="form" enctype="multipart/form-data">
Please or to participate in this conversation.