Laravel - "Unable to write in the "/var/www/html/laraapp/public/storage/documents/appraisal_goal“目录”

Laravel - "Unable to write in the "/var/www/html/laraapp/public/storage/documents/appraisal_goal" directory"

我在使用 Ubuntu-18 的 Digital Ocean 上部署了我的 Laravel-5.8 应用程序。当我想将图像保存到我在 Digital Ocean 上的 Laravel 应用程序时:

public function create()
{
    $userCompany = Auth::user()->company_id;
    $userEmployee = Auth::user()->employee_id;

    $identities = DB::table('appraisal_identity')->select('id','appraisal_name')->where('company_id', $userCompany)->where('is_current', 1)->first();
    $employees = DB::table('hr_employees')->select('id')->where('id', $userEmployee)->first();

  //  dd($employees);

    $goaltypes   =       AppraisalGoalType::where('company_id', $userCompany)->get(); 
     $categories = AppraisalGoalType::with('children')->where('company_id', $userCompany)->whereNull('parent_id')->get();

    return view('appraisal.appraisal_goals.create')
            ->with('goaltypes', $goaltypes)
            ->with('categories', $categories)
            ->with('identities', $identities)
            ->with('employees', $employees)
            ;
}

public function store(StoreAppraisalGoalRequest $request)
{

    $appraisalStartDate = Carbon::parse($request->appraisal_start_date);
    $appraisalEndDate = Carbon::parse($request->appraisal_end_date);        
    $userCompany = Auth::user()->company_id;
    $employeeId = Auth::user()->employee_id;
      $identities = DB::table('appraisal_identity')->select('id','appraisal_name')->where('company_id', $userCompany)->where('is_current', 1)->first();
      $employees = DB::table('hr_employees')->select('id')->where('id', $employeeId)->first();
  DB::beginTransaction(); 
      try {
        $goal = new AppraisalGoal();
        $goal->goal_type_id             = $request->goal_type_id;
        $goal->appraisal_identity_id    = $request->appraisal_identity_id;
        $goal->employee_id              = $request->employee_id;  //$employeeId;   //$request->employees_id
        $goal->weighted_score           = $request->weighted_score;
        $goal->goal_title               = $request->goal_title;
        $goal->goal_description         = $request->goal_description;
        $goal->company_id               = Auth::user()->company_id;
        $goal->created_by               = Auth::user()->id;
        $goal->created_at               = date("Y-m-d H:i:s");
        $goal->is_active                = 1;

             if ($request->appraisal_doc != "") {
                 $appraisal_doc = $request->file('appraisal_doc');
                 $new_name = rand() . '.' . $appraisal_doc->getClientOriginalExtension();
                 $appraisal_doc->move(public_path('storage/documents/appraisal_goal'), $new_name);
                 $goal->appraisal_doc = $new_name;
            }  

    $goal->save();        

        foreach ( $request->activity as $key => $activity){
            $startDate = Carbon::parse($request->start_date[$key]);
            $endDate = Carbon::parse($request->end_date[$key]);

           $goaldetail = new AppraisalGoalDetail();

            $goaldetail->kpi_description            = $request->kpi_description[$key];
            $goaldetail->appraisal_doc              = $request->application_doc[$key];
            $goaldetail->activity                   = $request->activity[$key];  
            $goaldetail->start_date                 = $startDate ->toDateTimeString();
            $goaldetail->end_date                   = $endDate->toDateTimeString();                  
            $goaldetail->appraisal_goal_id          = $goal->id;
            $goaldetail->appraisal_identity_id      = $goal->appraisal_identity_id;
            $goaldetail->employee_id                = $goal->employee_id;
            $goaldetail->company_id                 = Auth::user()->company_id;
            $goaldetail->created_by                 = Auth::user()->id;
            $goaldetail->created_at                 = date("Y-m-d H:i:s");
            $goaldetail->is_active                  = 1;
            $goaldetail->save();

         }
        $min_date = AppraisalGoalDetail::select('start_date')->where('appraisal_goal_id', $goal->id)->min('start_date');
        $max_date = AppraisalGoalDetail::select('end_date')->where('appraisal_goal_id', $goal->id)->max('end_date');   
        $parentid = AppraisalGoalType::select('parent_id')->whereNotNull('parent_id')->where('company_id', $userCompany)->where('id', $goal->goal_type_id)->first();

         $goal->update([
             'appraisal_start_date' => $min_date,
             'appraisal_end_date'   => $max_date,
             'parent_id'            => $parentid->parent_id
                 ]);

    DB::commit(); 

            Session::flash('success', 'Appraisal Goal is created successfully');
            return redirect()->route('appraisal.appraisal_goals.index');
    } catch (Exception $exception) {
        dd($exception->getMessage());
    DB::rollback();

            Session::flash('error', 'Action failed! Please try again');
            return redirect()->route('appraisal.appraisal_goals.index');
    }
}

在本地服务器上一切正常。但是当我将它在线部署到 Digital Ocean 时。然后,当我点击提交时,我得到了这个错误:

"Unable to write in the "/var/www/html/laraapp/public/storage/documents/appraisal_goal" directory"

如何解决?

谢谢

您没有写入 storage 文件夹所需的权限。

执行以下命令以提供必要的权限以写入 storage 文件夹

chmod 755 -R /var/www/html/laraapp/public/storage 

chown www-data:www-data /var/www/html/laraapp/public/storage