-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from digitalsign/master
修复 #1 路由缓存报错的问题
- Loading branch information
Showing
2 changed files
with
44 additions
and
34 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,3 @@ | ||
<?php | ||
|
||
Route::post('_grid-sortable_', function (\Illuminate\Http\Request $request) { | ||
|
||
$sorts = $request->get('_sort'); | ||
|
||
$sorts = collect($sorts) | ||
->pluck('key') | ||
->combine( | ||
collect($sorts)->pluck('sort')->sort() | ||
); | ||
|
||
$status = true; | ||
$message = trans('admin.save_succeeded'); | ||
$modelClass = $request->get('_model'); | ||
|
||
try { | ||
/** @var \Illuminate\Database\Eloquent\Collection $models */ | ||
$models = $modelClass::find($sorts->keys()); | ||
|
||
foreach ($models as $model) { | ||
|
||
$column = data_get($model->sortable, 'order_column_name', 'order_column'); | ||
|
||
$model->{$column} = $sorts->get($model->getKey()); | ||
$model->save(); | ||
} | ||
|
||
} catch (Exception $exception) { | ||
$status = false; | ||
$message = $exception->getMessage(); | ||
} | ||
|
||
return response()->json(compact('status', 'message')); | ||
|
||
})->name('laravel-admin-grid-sortable'); | ||
Route::post('_grid-sortable_', '\Encore\Admin\GridSortable\Controllers\GridSortableController@sort')->name('laravel-admin-grid-sortable'); |
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 Encore\Admin\GridSortable\Controllers; | ||
|
||
use Exception; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Routing\Controller; | ||
|
||
class GridSortableController extends Controller | ||
{ | ||
public function sort(Request $request) | ||
{ | ||
$sorts = $request->get('_sort'); | ||
|
||
$sorts = collect($sorts) | ||
->pluck('key') | ||
->combine( | ||
collect($sorts)->pluck('sort')->sort() | ||
); | ||
|
||
$status = true; | ||
$message = trans('admin.save_succeeded'); | ||
$modelClass = $request->get('_model'); | ||
|
||
try { | ||
/** @var \Illuminate\Database\Eloquent\Collection $models */ | ||
$models = $modelClass::find($sorts->keys()); | ||
|
||
foreach ($models as $model) { | ||
|
||
$column = data_get($model->sortable, 'order_column_name', 'order_column'); | ||
|
||
$model->{$column} = $sorts->get($model->getKey()); | ||
$model->save(); | ||
} | ||
} catch (Exception $exception) { | ||
$status = false; | ||
$message = $exception->getMessage(); | ||
} | ||
|
||
return response()->json(compact('status', 'message')); | ||
} | ||
} |