我在Laravel中创建了一项功能,允许用户记录费用。我想让他们选择上传收据的照片/ pdf。
在迁移过程中保存此内容的正确数据类型是什么。显而易见,它不是字符串。
我正在使用laravel,并将其存储在phpmyadmin数据库中。
答案 0 :(得分:0)
your Migration
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEmployeeExpensesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('employee_expenses', function (Blueprint $table) {
$table->increments('id');
$table->bigInteger('employee_id');
$table->string('expense_name');
$table->date('paid_on');
$table->string('amount');
$table->longText('description');
$table->string('file')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('employee_expenses');
}
}
存储数据
public function store(expensesFormRequest $request){
$input = $request->all();
$file = $request->file('file');
if(!empty($file)){
$this->validate($request,[
'file' =>'mimes:jpeg,bmp,png,csv,txt,doc,docx,pdf'
]);
$fileUploadName = $this->uploadFile($file);
$input['file'] = $fileUploadName;
}
$paidOn = explode('/',$input['paid_on']);
$date = $paidOn[2].'-'.$paidOn[1].'-'.$paidOn[0];
$input['paid_on'] = $date;
unset($input['_token']);
employeeExpenses::create($input);
/*inseting in lig table*/
applicationLog::create(['type'=>'Create',
'message'=>'An employee expense is created',
'source'=>'employee expense created ']);
return redirect()->route('expenses.index')->with('success','Employee expenses created successfully');
}
public function uploadFile($file){
$extension = $file->getClientOriginalExtension();
$fileName = time().'.'.$extension;
$path = public_path().'/adminExpenses';
$uplaod = $file->move($path,$fileName);
return $fileName;
}