FIX: fix few minor bugs
This commit is contained in:
@@ -3,15 +3,32 @@ namespace App\CMS\Repositories\FileManager;
|
|||||||
|
|
||||||
use App\CMS\Helpers\RootDirectory;
|
use App\CMS\Helpers\RootDirectory;
|
||||||
use App\Models\FileManager\Directory as DirectoryModel;
|
use App\Models\FileManager\Directory as DirectoryModel;
|
||||||
use App\Models\FileManager\File;
|
|
||||||
|
|
||||||
class Directory
|
class Directory
|
||||||
{
|
{
|
||||||
public function checkIfNameExists($name, $directoryId)
|
/**
|
||||||
|
* Checks if directory with given name does not exist in current directory
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
* @param $parentDirectoryId
|
||||||
|
* @param bool $ignoredId
|
||||||
|
*/
|
||||||
|
public function checkIfNameExists($name, $parentDirectoryId, $ignoredId = false)
|
||||||
{
|
{
|
||||||
return DirectoryModel::where('name', $name)
|
$exists = DirectoryModel::where('name', $name)
|
||||||
->where('parent_id', $directoryId)
|
->where('parent_id', $parentDirectoryId);
|
||||||
->exists();
|
|
||||||
|
if ($ignoredId !== false) {
|
||||||
|
$exists = $exists->where('id', '!=', $ignoredId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $exists->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(DirectoryModel $directory, $data) {
|
||||||
|
$directory->name = $data['name'];
|
||||||
|
$directory->description = $data['description'];
|
||||||
|
$directory->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin\FileManager;
|
namespace App\Http\Controllers\Admin\FileManager;
|
||||||
|
|
||||||
|
use App\CMS\Repositories\FileManager\Directory as DirectoryRepository;
|
||||||
use App\Http\Controllers\Admin\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use App\Models\FileManager\Directory;
|
use App\Models\FileManager\Directory;
|
||||||
@@ -16,30 +17,21 @@ class EditDirectory extends Controller
|
|||||||
* @internal param $directoryId
|
* @internal param $directoryId
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function postEdit(Requests\EditDirectoryRequest $request, Directory $directory)
|
public function update(Requests\EditDirectoryRequest $request, Directory $directory)
|
||||||
{
|
{
|
||||||
// check if given name is not used in parent directory
|
$repository = app(DirectoryRepository::class);
|
||||||
|
if ($repository->checkIfNameExists($request->name, $directory->parent_id, $directory->id)) {
|
||||||
$exists = Directory::where('parent_id', $directory->parent_id)
|
|
||||||
->where('name', $request->name)
|
|
||||||
->where('id', '!=', $directory->id)
|
|
||||||
->exists();
|
|
||||||
|
|
||||||
if ($exists) {
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('upload.overview', ['id' => $directory->id])
|
->back()
|
||||||
->withInput()
|
->withInput()
|
||||||
->with('error', trans('admin/fileManager.subdirectoryExists'));
|
->with('error', trans('admin/fileManager.subdirectoryExists'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$directory->name = $request->name;
|
$repository->update($directory, $request->except('_token'));
|
||||||
$directory->description = $request->description;
|
|
||||||
|
|
||||||
$directory->save();
|
|
||||||
|
|
||||||
$message = trans('admin/fileManager.editDirectorySuccess');
|
$message = trans('admin/fileManager.editDirectorySuccess');
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('upload.overview', ['id' => $directory->id])
|
->back()
|
||||||
->with('success', $message);
|
->with('success', $message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
Route::group([
|
Route::group([
|
||||||
'prefix' => LaravelLocalization::setLocale(),
|
'prefix' => LaravelLocalization::setLocale(),
|
||||||
'middleware' => ['localeSessionRedirect', 'localizationRedirect'],
|
|
||||||
'namespace' => 'Modules\Blog\Article\Http\Controllers'
|
'namespace' => 'Modules\Blog\Article\Http\Controllers'
|
||||||
], function () {
|
], function () {
|
||||||
Route::group([
|
Route::group([
|
||||||
'middleware' => ['web', 'auth', 'adminMenu'],
|
'middleware' => ['admin'],
|
||||||
'prefix' => 'admin/comments',
|
'prefix' => 'admin/comments',
|
||||||
'namespace' => 'Admin'
|
'namespace' => 'Admin'
|
||||||
], function () {
|
], function () {
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
<form method="POST" action="{{$action}}">
|
<form method="POST" action="{{$action}}">
|
||||||
{!! csrf_field() !!}
|
{!! csrf_field() !!}
|
||||||
<input type="text" name="name" placeholder="@lang('admin/fileManager.directoryName')" class="form-control"
|
<input type="text" name="name" required placeholder="@lang('admin/fileManager.directoryName')" class="form-control"
|
||||||
value="{{old('name', $directory->name)}}" />
|
value="{{old('name', $directory->name)}}" />
|
||||||
|
|
||||||
<textarea name="description" class="form-control" placeholder="@lang('admin/fileManager.directoryDescription')"
|
<textarea name="description" class="form-control" placeholder="@lang('admin/fileManager.directoryDescription')"
|
||||||
rows="3">{{old('description', $directory->description)}}</textarea>
|
rows="3">{{old('description', $directory->description)}}</textarea>
|
||||||
|
|
||||||
|
|
||||||
@if ($parentDirectory->id)
|
@if ($parentDirectory->id)
|
||||||
<input type="text" name="parentDirectory" value="{{$parentDirectory->id}}">
|
<input type="hidden" name="parentDirectory" value="{{$parentDirectory->id}}">
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">
|
<button type="submit" class="btn btn-primary">
|
||||||
@@ -17,7 +16,5 @@
|
|||||||
@else
|
@else
|
||||||
@lang('admin/fileManager.newDirectory')
|
@lang('admin/fileManager.newDirectory')
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
Reference in New Issue
Block a user