Skip to content

Commit

Permalink
Added Laravel Filemanager
Browse files Browse the repository at this point in the history
  • Loading branch information
stanfortonski committed Jul 18, 2021
1 parent d63d9b1 commit b8a57c2
Show file tree
Hide file tree
Showing 54 changed files with 2,437 additions and 251 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ In config/fortify.php uncomment Features::registration() and then in config/blog
- [Laravel 8.x](https://laravel.com/docs/8.x)
- [Laravel Fortify](https://github.com/laravel/fortify)
- [Laravel-Roles](https://github.com/stanfortonski/Laravel-Roles)
- [Laravel Filemanager](https://github.com/UniSharp/laravel-filemanager)
- [Laravel-Feed](https://github.com/spatie/laravel-feed)
- [CoreUI 3.x](https://coreui.io)
- [TinyMCE](https://tiny.cloud/)
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public function index(Request $request)
return view('admin.index');
}

public function filesManager()
{
return view('admin.files-manager');
}

public function setLang($lang)
{
Cookie::queue('lang', $lang);
Expand Down
9 changes: 2 additions & 7 deletions app/Http/Controllers/Admin/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
use App\Models\Category;
use App\Models\Content;
use App\Services\CategoryContentUrlValidator;
use App\Services\ContentUrlValidator;
use App\Services\ThumbnailManager;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class CategoriesController extends Controller
{
use ThumbnailManager, CategoryContentUrlValidator;
use CategoryContentUrlValidator;

/**
* Display a listing of the resource.
Expand Down Expand Up @@ -61,7 +59,6 @@ public function store(CategoryStoreRequest $request)
DB::beginTransaction();
try {
$data = $this->getValidatedData($request);
$data['thumbnail_path'] = $this->storeThumbnail($request);
$category = Category::create($data);

$content = Content::create($request->content);
Expand Down Expand Up @@ -155,8 +152,7 @@ public function destroy(Category $category)
*/
public function updateImage(ImageRequest $request, Category $category)
{
$this->deleteThumbnail($category);
$category->thumbnail_path = $this->storeThumbnail($request);
$category->thumbnail_path = $request->thumbnail_path;
$category->update();

return redirect()->back()->withSuccess('admin.thumbnail.update');
Expand All @@ -170,7 +166,6 @@ public function updateImage(ImageRequest $request, Category $category)
*/
public function destroyImage(Category $category)
{
$this->deleteThumbnail($category);
$category->thumbnail_path = null;
$category->update();

Expand Down
10 changes: 3 additions & 7 deletions app/Http/Controllers/Admin/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
use App\Models\PostContent;
use App\Models\Post;
use App\Services\PostContentUrlValidator;
use App\Services\ThumbnailManager;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Exception;
use Illuminate\Support\Facades\Log;

class PostsController extends Controller
{
use ThumbnailManager, PostContentUrlValidator;
use PostContentUrlValidator;

/**
* Display a listing of the resource.
Expand Down Expand Up @@ -61,7 +60,6 @@ public function store(PostStoreRequest $request)
DB::beginTransaction();
try {
$data = $this->getValidatedData($request);
$data['thumbnail_path'] = $this->storeThumbnail($request);
$post = Post::create($data);

$this->saveCategories($request, $post);
Expand Down Expand Up @@ -169,8 +167,7 @@ public function destroy(Post $post)
public function updateImage(ImageRequest $request, Post $post)
{
if ($post->user_id == auth()->user()->id || auth()->user()->hasOneOfRoles(['admin', 'mod'])){
$this->deleteThumbnail($post);
$post->thumbnail_path = $this->storeThumbnail($request);
$post->thumbnail_path = $request->thumbnail_path;
$post->update();

return redirect()->back()->withSuccess('admin.thumbnail.update');
Expand All @@ -187,7 +184,6 @@ public function updateImage(ImageRequest $request, Post $post)
public function destroyImage(Post $post)
{
if ($post->user_id == auth()->user()->id || auth()->user()->hasOneOfRoles(['admin', 'mod'])){
$this->deleteThumbnail($post);
$post->thumbnail_path = null;
$post->update();

Expand All @@ -212,7 +208,7 @@ private function getValidatedData(PostStoreRequest $request): array
unset($data['publish_at_date']);
unset($data['publish_at_time']);
}
unset($data['content'], $data['thumbnail'], $data['categories']);
unset($data['content'], $data['categories']);
return $data;
}

Expand Down
15 changes: 0 additions & 15 deletions app/Http/Controllers/Admin/TinymceImageController.php

This file was deleted.

7 changes: 1 addition & 6 deletions app/Http/Controllers/Admin/UserPanelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use App\Http\Requests\ImageRequest;
use App\Rules\IsLang;
use App\Rules\RealName;
use App\Services\ThumbnailManager;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
Expand All @@ -21,8 +20,6 @@

class UserPanelController extends Controller
{
use ThumbnailManager;

public function index()
{
return view('admin.user-panel.index')->with('user', auth()->user());
Expand Down Expand Up @@ -113,8 +110,7 @@ public function updatePassword(UserPasswordRequest $request)
public function updateImage(ImageRequest $request)
{
$user = auth()->user();
$this->deleteThumbnail($user);
$user->thumbnail_path = $this->storeThumbnail($request);
$user->thumbnail_path = $request->thumbnail_path;
$user->update();

return redirect()->back()->withSuccess('admin.thumbnail.update');
Expand All @@ -128,7 +124,6 @@ public function updateImage(ImageRequest $request)
public function destroyImage()
{
$user = auth()->user();
$this->deleteThumbnail($user);
$user->thumbnail_path = null;
$user->update();

Expand Down
8 changes: 1 addition & 7 deletions app/Http/Controllers/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use App\Models\AuthorContent;
use App\Models\User;
use App\Http\Requests\ImageRequest;
use App\Services\ThumbnailManager;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
Expand All @@ -20,8 +19,6 @@

class UsersController extends Controller
{
use ThumbnailManager;

/**
* Display a listing of the resource.
*
Expand Down Expand Up @@ -62,7 +59,6 @@ public function store(UserStoreRequest $request)
DB::beginTransaction();
try {
$data = $this->getValidatedData($request);
$data['thumbnail_path'] = $this->storeThumbnail($request);

$user = User::create($data);
$this->saveRoles($request, $user);
Expand Down Expand Up @@ -154,8 +150,7 @@ public function destroy(User $user)
*/
public function updateImage(ImageRequest $request, User $user)
{
$this->deleteThumbnail($user);
$user->thumbnail_path = $this->storeThumbnail($request);
$user->thumbnail_path = $request->thumbnail_path;
$user->update();

return redirect()->back()->withSuccess('admin.thumbnail.update');
Expand All @@ -170,7 +165,6 @@ public function updateImage(ImageRequest $request, User $user)
*/
public function destroyImage(User $user)
{
$this->deleteThumbnail($user);
$user->thumbnail_path = null;
$user->update();

Expand Down
4 changes: 1 addition & 3 deletions app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ class VerifyCsrfToken extends Middleware
*
* @var array
*/
protected $except = [
'/upload'
];
protected $except = [];
}
4 changes: 2 additions & 2 deletions app/Http/Requests/CategoryStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function attributes()
'content.lang' => __('lang'),
'content.content' => __('content'),
'content.url' => __('url'),
'thumbnail' => __('thumbnail')
'thumbnail_path' => __('thumbnail')
];
}

Expand All @@ -39,7 +39,7 @@ public function rules()
'content.lang' => ['required', 'string', new IsLang],
'content.url' => ['required', 'string', 'max:255', new PartOfUrl],
'content.content' => ['required', 'string', 'max:65535'],
'thumbnail' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:2048']
'thumbnail_path' => ['nullable', 'string', 'max:255']
];
}
}
4 changes: 2 additions & 2 deletions app/Http/Requests/ImageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function authorize()
public function attributes()
{
return [
'thumbnail' => __('thumbnail')
'thumbnail_path' => __('thumbnail')
];
}

Expand All @@ -36,7 +36,7 @@ public function attributes()
public function rules()
{
return [
'thumbnail' => ['required', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:2048'],
'thumbnail_path' => ['nullable', 'string', 'max:255'],
];
}
}
4 changes: 2 additions & 2 deletions app/Http/Requests/PostStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function attributes()
'content.content' => __('content'),
'content.url' => __('url'),
'publish_at' => __('publish at'),
'thumbnail' => __('thumbnail'),
'thumbnail_path' => __('thumbnail'),
'categories' => __('Categories'),
'tags' => __('Tags')
];
Expand All @@ -54,7 +54,7 @@ public function rules()
'content.content' => ['required', 'string', 'max:65535'],
'publish_at_date' => ['nullable', 'date'],
'publish_at_time' => ['nullable', 'date_format:H:i'],
'thumbnail' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:2048'],
'thumbnail_path' => ['nullable', 'string', 'max:255'],
'categories' => ['nullable', 'array'],
'categories.*' => ['nullable', 'integer', 'exists:categories,id'],
'tags' => ['nullable', 'string', 'max:255']
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/UserStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function attributes()
'last_name' => __('Last Name'),
'content' => __('content'),
'website' => __('website'),
'thumbnail' => __('thumbnail'),
'thumbnail_path' => __('thumbnail'),
'roles' => __('Roles'),
'password' => __('Password')
];
Expand All @@ -50,7 +50,7 @@ public function rules()
'email' => ['required', 'email'],
'content' => ['nullable', 'string', 'max:255'],
'website' => ['nullable', 'url', 'max:255'],
'thumbnail' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:2048'],
'thumbnail_path' => ['nullable', 'string', 'max:255'],
'roles' => ['nullable', 'array'],
'roles.*' => ['nullable', 'integer', 'exists:roles,id'],
'password' => ['sometimes', 'string', new Password]
Expand Down
4 changes: 0 additions & 4 deletions app/Observers/CategoryObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace App\Observers;

use App\Models\Category;
use App\Services\ThumbnailManager;

class CategoryObserver
{
use ThumbnailManager;

/**
* Handle the Category "created" event.
*
Expand Down Expand Up @@ -40,7 +37,6 @@ public function updated(Category $category)
public function deleting(Category $category)
{
$category->contents()->delete();
$this->deleteThumbnail($category);
}

/**
Expand Down
4 changes: 0 additions & 4 deletions app/Observers/PostObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace App\Observers;

use App\Models\Post;
use App\Services\ThumbnailManager;

class PostObserver
{
use ThumbnailManager;

/**
* Handle the Post "created" event.
*
Expand Down Expand Up @@ -40,7 +37,6 @@ public function updated(Post $post)
public function deleting(Post $post)
{
$post->contents()->delete();
$this->deleteThumbnail($post);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions app/Observers/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace App\Observers;

use App\Models\User;
use App\Services\ThumbnailManager;

class UserObserver
{
use ThumbnailManager;

/**
* Handle the User "created" event.
*
Expand Down Expand Up @@ -45,8 +42,6 @@ public function deleting(User $user)
$user->posts()->each(function($post){
$post->delete();
});

$this->deleteThumbnail($user);
}

/**
Expand Down
25 changes: 0 additions & 25 deletions app/Services/ThumbnailManager.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/Traits/HasThumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ trait HasThumbnail
{
public function getThumbnailAttribute()
{
return asset('storage/thumbnails/'.$this->thumbnail_path);
return $this->thumbnail_path;
}
}
Loading

0 comments on commit b8a57c2

Please sign in to comment.