-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d0c195
commit 85ee8ac
Showing
3,149 changed files
with
745 additions
and
46,789 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Episode; | ||
use App\Http\Requests\EpisodeRequest; | ||
use App\Http\Controllers\Admin\AdminController; | ||
use Illuminate\Http\Request; | ||
|
||
class EpisodeController extends AdminController | ||
{ | ||
public function __construct(){ | ||
$this->middleware('can:create_episode')->only(['create']); | ||
$this->middleware('can:delete_episode')->only(['destroy']); | ||
$this->middleware('can:edit_episode')->only(['edit','update']); | ||
$this->middleware('can:show_episodes')->only(['index']); | ||
} | ||
|
||
/** | ||
* Display a listing of the resource. | ||
*/ | ||
public function index() | ||
{ | ||
$episodes = Episode::query(); | ||
if($keyword = request('search')){ | ||
$episodes-> where('title','like',"%$keyword%")->orWhere('body','like',"%$keyword%") | ||
->orWhere('id',$keyword); | ||
} | ||
|
||
$episodes = $episodes->latest()->paginate(100); | ||
return view('admin.episodes.index',compact('episodes')); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
*/ | ||
public function create() | ||
{ | ||
return view('admin.episodes.create'); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
*/ | ||
public function store(EpisodeRequest $request) | ||
{ | ||
$videoUrl = $this->uploadVideos($request->file('videos')); | ||
if ($videoUrl) { | ||
$episodes = Episode::create(array_merge($request->all(), ['videos' => $videoUrl])); | ||
} else { | ||
$episodes = Episode::create($request->all()); | ||
} | ||
|
||
$this->setCourseTime($episodes); | ||
|
||
return redirect(url('/admin/episodes')); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
*/ | ||
public function show(Episode $episode) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
*/ | ||
public function edit(string $id) | ||
{ | ||
$episode = Episode::find($id); | ||
return view('admin.episodes.edit', compact('episode')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
*/ | ||
public function update(Request $request, string $id) | ||
{ | ||
$file = $request->file('videos'); | ||
$episode = Episode::find($id); | ||
|
||
$inputs = $request->all(); | ||
if ($file) { | ||
$inputs['videos'] = $this->uploadVideos($request->file('videos')); | ||
} | ||
|
||
$episode->update($inputs); | ||
$this->setCourseTime($episode); | ||
|
||
return redirect(route('admin.episodes.index')); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
*/ | ||
public function destroy(string $id) | ||
{ | ||
$episode = Episode::find($id); | ||
$episode-> delete(); | ||
|
||
return redirect(route('admin.episodes.index')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class EpisodeRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'title'=>'required', | ||
'type'=>'required', | ||
'body'=>'required', | ||
'slug'=>'required', | ||
'number'=>'required', | ||
'time'=>'required', | ||
'tags'=>'required', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Episode extends Model | ||
{ | ||
protected $fillable = ['course_id','title', 'type', 'slug', 'body', 'videoUrl', 'tags', 'download_count', 'videos', 'time', 'view_count', 'comment_count', 'number']; | ||
|
||
public function course() | ||
{ | ||
return $this->belongsTo(Course::class); | ||
} | ||
|
||
protected $casts = [ | ||
'videos'=>'array' | ||
]; | ||
|
||
public function download() | ||
{ | ||
if (! auth()->check()) return '#'; | ||
$status = false; | ||
switch ($this->type){ | ||
case 'free' : | ||
$status = true; | ||
break; | ||
case 'vip' : | ||
if (auth()->user()->isActive()) $status = true; | ||
break; | ||
case 'cash' : | ||
if (auth()->user()->checkLearning($this->course)) $status = true; | ||
break; | ||
} | ||
|
||
$timestamp = Carbon::now()->addHour(5)->timestamp; | ||
$hash = Hash::make('t@d@d@t@sj45n43js43dn#*d'.$this->id.request()->ip().$timestamp); | ||
|
||
return $status ? "/download/$this->id?mac=$hash&t=$timestamp" : "#"; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
database/migrations/2023_08_05_004417_create_episodes_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('episodes', function (Blueprint $table) { | ||
$table->id(); | ||
$table->bigInteger('course_id')->unsigned()-> index()-> nullable(); | ||
$table->foreign('course_id')->references('id')->on('courses')->onUpdate('cascade'); | ||
$table->string('title'); | ||
$table->string('type',10); | ||
$table->string('slug'); | ||
$table->text('body'); | ||
$table->text('videos')->nullable(); | ||
$table->text('videoUrl')->nullable(); | ||
$table->string('tags'); | ||
$table->string('time',15)->default('00:00:00'); | ||
$table->integer('number'); | ||
$table->string('view_count')->default(0); | ||
$table->string('comment_count')->default(0); | ||
$table->string('download_count')->default(0); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('episodes'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ | |
RewriteCond %{REQUEST_FILENAME} !-d | ||
RewriteCond %{REQUEST_FILENAME} !-f | ||
RewriteRule ^ index.php [L] | ||
|
||
</IfModule> |
Oops, something went wrong.