where('user_id', auth()->id()) ->first(); if (!$studioPlusChannel) { $studioPlusChannel = StudioPlusChannel::create([ 'user_id' => auth()->id(), 'name' => Str::random(30) ]); } return redirect()->route('studio-plus.channel', [ 'studioPlusChannel' => $studioPlusChannel->name ]); } public function show(StudioPlusChannel $studioPlusChannel) { $videos = $this->getInitialVideos(); return view('studioplus::show', [ 'channel' => $studioPlusChannel, 'videos' => $videos ]); } public function studio(StudioPlusChannel $studioPlusChannel) { $columns = ColumnPreset::where('user_id', auth()->id())->first(); $videos = $this->getInitialVideos(); $current_month = Carbon::now()->month; $current_year = Carbon::now()->year; $start_date = Carbon::create($current_year, $current_month, 1)->startOfDay(); $end_date = $start_date->copy()->endOfMonth(); return view('studioplus::studio', [ 'channel' => $studioPlusChannel, 'videos' => $videos, 'columns' => $columns, 'start_date' => $start_date, 'end_date' => $end_date ]); } public function videos() { return view('studioplus::video'); } public function watch(Request $request, StudioPlusVideo $video) { $original = false; if ($request->has('original')) { $original = true; } return view('studioplus::watch', [ 'video' => $video->load('comments'), 'channel' => $video->channel, 'original' => $original ]); } public function getProductDetails(Request $request) { $code = $request->asin; if (preg_match('/^[A-Z0-9]{10}$/', $code)) { $service = new AmazonProductService(); } else { $service = new ProductBarcodeService(); } return $service->getProductDetails($request->asin); } public function getInitialVideos($user_id = null) { $studioPlusChannel = StudioPlusChannel::query() ->where('user_id', auth()->id()) ->first(); $query = auth()->user()->role->type === 'superadmin' || permissionCheck('studioplus.manage.videos') ? StudioPlusVideo::query() : StudioPlusVideo::query() ->where( fn ($query) => $query->where('studio_plus_channel_id', $studioPlusChannel->id) ); $current_month = Carbon::now()->month; $current_year = Carbon::now()->year; $start_date = Carbon::create($current_year, $current_month, 1)->startOfDay(); $end_date = $start_date->copy()->endOfMonth(); $videos = $query->with([ 'thumbnail', //'thumbnails', 'category', 'videoType', 'asinData', 'channel.user', 'urls', ]) ->whereBetween('created_at', [$start_date, $end_date]) //->where('status', 'All') /*->filter($request) ->when($request->filled('category_id'), fn ($query) => $query->where('studio_plus_category_id', $request->category_id)) ->when($request->filled('status') && $request->status !== 'All' && $request->status !== 'MVL', fn ($query) => $query->where('status', $status)) ->when($request->filled('start_date') && $request->filled('end_date'), fn ($query) => $query->whereBetween(DB::raw('DATE(created_at)'), [$request->start_date, $request->end_date])) ->when($request->filled('user_id'), function($query) use($request) { $query->whereHas('channel.user', function($query) use($request) { $query->where('id', $request->user_id); }); }) ->when($request->filled('team_leader_id'), fn ($query) => $query->whereHas('channel.user', fn ($query) => $query->where('parent_id', $request->team_leader_id)->orWhere('id', $request->team_leader_id) ) ) ->when($request->filled('type'), function($query) use($request) { if ($request->type == 'SHORTS') { $query->where('is_short', true); } else { $query->whereJsonContains('types', [$request->type]); } }) ->when($request->filled('orderBy') && $request->filled('sortBy'), function ($query) use ($request) { if ($request->orderBy === 'category') { $query->orderBy(StudioPlusCategory::select('name')->whereColumn('id', 'studio_plus_category_id')->orderBy('name', $request->sortBy), $request->sortBy); } else if ($request->orderBy === 'asin_data') { $query->orderBy(StudioPlusAsin::select('range_amount')->whereColumn('id', 'studio_plus_asin_id')->orderBy('range_amount', $request->sortBy), $request->sortBy); } else if ($request->orderBy === 'first_name') { $query->leftJoin('studio_plus_channels as channel', 'channel.id', '=', 'studio_plus_videos.studio_plus_channel_id') ->leftJoin('users', 'users.id', '=', 'channel.user_id') ->select('studio_plus_videos.*') ->orderBy($request->orderBy, $request->sortBy); } else if ($request->orderBy === 'video_types') { $query->orderBy('types', $request->sortBy); } else { $query->orderBy($request->orderBy, $request->sortBy); } }, fn ($query) => $query->latest())*/ //->skip($page * $rows) ->latest() ->skip(0) ->take(25) ->get(); return $videos; } public function viewUserChannel(Request $request, StudioPlusChannel $channel) { $columns = ColumnPreset::where('user_id', auth()->id())->first(); $videos = $this->getInitialVideos(); $current_month = Carbon::now()->month; $current_year = Carbon::now()->year; $start_date = Carbon::create($current_year, $current_month, 1)->startOfDay(); $end_date = $start_date->copy()->endOfMonth(); return view('studioplus::studio', [ 'channel' => $channel, 'videos' => $videos, 'columns' => $columns, 'start_date' => $start_date, 'end_date' => $end_date, 'user_id' => $request->has('user_id') ? $request->user_id : null ]); } public function studioSettings() { return view('studioplus::settings'); } public function urlLabelsManager() { return view('studioplus::studio-url-labels-manager'); } public function resolutionsManager() { return view('studioplus::studio-video-resolutions-manager'); } }