簡體   English   中英

我無法更改 Controller 在 Laravel 8 中的位置

[英]I can not change Controller locaiton in Laravel 8

我有一個 Laravel 8 項目。 我需要更改控制器文件位置。 但我無法更改文件位置。 例如,我將HomeController移動到App\Http\Controllers\Admin而不是App\Http\Controllers 然后我更新了我在路由部分使用web.php中的 use 命令定義的控制器。 下面我保留了HomeControllerweb.php的相關部分。 你可以去那里看看。 完成所有這些后,當我從本地主機刷新我的頁面時,出現屏幕截圖中的錯誤。 我不明白我錯過了什么。

在此處輸入圖像描述

web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\{
    AdminController,
    AwsTranscoderController,
    AwsTranscribeController,
    CategoryController,
    ContentController,
    Controller,
    CourseController,
    CreatorApplicationController,
    CreatorController,
    DevController,
    HomeController,
    LearnBiteController,
    NotificationsController,
    NotionApiController,
    PayoutController,
    PromotionalCodeController,
    RecomendationEngineController,
    RequestPayoutController,
    SubscriberController,
    TagController,
    UserTagController,
};

use App\Http\Controllers\Tools\{
    AnalyticsToolController,
    PayoutAlgorithmController,
};

use App\Http\Controllers\DevelopmentTools\{
    EmailTestController,
    GeneralToolsController,
};

家庭控制器

<?php

namespace App\Http\Controllers;

use App\Course;
use App\CourseLecture;
use App\CreatorApplicationForm;
use App\CreatorProfile;
use App\RawListeningData;
use App\User;
use App\UserPayment;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class HomeController extends Controller 
{

    public $raw_listening;
    public $all_learnbite_id_list;
    public $all_learnbite_lecture_id_list;
    public $all_course_id_list;
    public $all_course_lecture_id_list;
    public $dashboard_data;
    public $creator_applications;
    public $submitted_content;


    public function __construct()
    {
        $this->middleware(['auth']);
    }



    public function index()
    {
        if(Auth::user()->role_id>2){
            $role = Auth::user()->role;
            auth()->logout();
            return redirect('/login');
        }
        $this->getRawListeningData();
        $this->getAllContent();
        $this->getDashboardData();
        $this->getCreatorApplications();
        $this->getSubmittedContent();

        $most_popular_5_course = $this->getMostPopular5Content(false);
        $most_popular_5_learnbite = $this->getMostPopular5Content(true);

        return view('admin.home',[
            'mostpopular_5_learnbite' => $most_popular_5_learnbite,
            'most_popular_5_course'=>$most_popular_5_course,
            'dashboard_data' =>$this->dashboard_data,
            'creator_applications' =>$this->creator_applications,
            'submitted_content' =>$this->submitted_content
            ]
        );
    }

    private function getRawListeningData($period="-1 week"){
        $this->raw_listening = RawListeningData::select('raw_listening_data.id','raw_listening_data.course_lecture_id','course_lectures.course_id','raw_listening_data.user_id','courses.user_id as creator_id')
            ->join('course_lectures', 'raw_listening_data.course_lecture_id', '=', 'course_lectures.id')
            ->join('courses', 'course_lectures.course_id', '=', 'courses.id')
            ->where([['raw_listening_data.created_at','>',date('Y-m-d',strtotime($period))]])
            ->get()
            ->groupBy('course_id')->collect()->sort()->reverse();
    }

    private function getSubmittedContent(){
        $this->submitted_content = Course::where('status_id','=',3)->get();
    }
    private function getCreatorApplications(){
        $this->creator_applications = CreatorApplicationForm::where('creator_id','=',null)->with('categoryCreator')->get();
    }
    private function getDashboardData(){
        $this->dashboard_data = collect([]);
        $courses = Course::select(['id','user_id','isLearnBite'])->where('status_id','=',1)->get();
        $listener = UserPayment::select(['id','user_id','price','period_type'])->where([['purchased_date','>=','2021-12-09']])->get();


        $creator_count = $courses->whereNotIn('user_id',[626,627])->groupBy('user_id')->count();
        $creator_profile = CreatorProfile::whereNotIn('user_id',[626,627])->count();
        $learnbite_count = $courses->whereNotIn('user_id',[626,627])->where('isLearnBite','=',true)->count();
        $course_count = $courses->whereNotIn('user_id',[626,627])->where('isLearnBite','=',false)->count();
        $listener_count = $listener->groupBy('user_id')->count();
        $trial_user_count = $listener->where('period_type','=',1)->groupBy('user_id')->count();
        $paid_user_count = $listener->where('period_type','=',3)->groupBy('user_id')->count();

        // $avarage_seconds = $this->getSessionDurationData();
        // TODO : Bu veri nasıl kullanılacak?

        $this->dashboard_data[] = collect(['title' => 'Creators with Profile','small' =>'','data' => $creator_profile]);
        $this->dashboard_data[] = collect(['title' => 'Creators with Content','small' =>'','data' => $creator_count]);
        $this->dashboard_data[] = collect(['title' => 'Published Courses','small' =>'','data' => $course_count]);
        $this->dashboard_data[] = collect(['title' => 'Published Learnbites','small' =>'','data' => $learnbite_count]);
        $this->dashboard_data[] = collect(['title' => 'Trial Listeners','small' =>'All Time','data' => $trial_user_count]);
        $this->dashboard_data[] = collect(['title' => 'Paid Listeners','small' =>'All Time','data' => $paid_user_count]);
    }


    private function getAllContent(){
      $this->all_learnbite_id_list =  DB::table('courses')->select('id')->where('isLearnBite','=',1)->get()->map(function ($content){
           return $content->id;
        });

      $this->all_course_id_list =  DB::table('courses')->select('id')->where('isLearnBite','=',0)->get()->map(function ($content){
           return $content->id;
        });

      $this->all_learnbite_lecture_id_list = DB::table('course_lectures')
          ->select('id')->whereIn('course_id',$this->all_learnbite_id_list)
          ->get()->map(function ($lecture){
          return $lecture->id;
      });

        $this->all_course_lecture_id_list = DB::table('course_lectures')
          ->select('id')->whereIn('course_id',$this->all_course_id_list)
          ->get()->map(function ($lecture){
          return $lecture->id;
      });
    }

    private function getMostPopular5Content($isLearnbite){
        $raw_data = collect($this->raw_listening)->filter(function ($data,$lecture_id) use ($isLearnbite){
                return  $isLearnbite ? $this->all_learnbite_lecture_id_list->contains($lecture_id) : $this->all_course_lecture_id_list->contains($lecture_id);
            });

        $result = $raw_data->map(function($value,$course_id){
            $course = Course::findorfail($course_id);
            $only_self =  $value->filter(function ($val) use($course){
               return  $val->user_id== $course->user_id;
            });
            $exclude_self =  $value->filter(function ($val) use($course){
               return  $val->user_id != $course->user_id;
            });
            $course->only_self = gmdate("H:i:s",  count($only_self));
            $course->listening_time = gmdate("H:i:s",  count($exclude_self));
            $course->different_user = count($exclude_self->groupBy('user_id'));
            
            return $course;
        });
        $result = $result->sortByDesc('listening_time');

        return $result->take(5);
    }
}

您移動了文件,但沒有更新名稱空間。

namespace App\Http\Controllers;

需要成為:

namespace App\Http\Controllers\Admin;

(大概還有一個非管理員 HomeController 與之沖突。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM