mirror of https://github.com/4xmen/xshop.git
added xcontroller commands
parent
22c6f45111
commit
c7f582ed46
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class makeXcontroller extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'make:xcontroller {model}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'create new xContoller';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
$model = ucfirst($this->argument('model'));
|
||||
$var = '$' . strtolower($this->argument('model'));
|
||||
|
||||
|
||||
if (!file_exists(__DIR__.'/../../Models/'.$model.'.php')){
|
||||
$this->error("Model not found!");
|
||||
return ;
|
||||
}
|
||||
|
||||
$content = file_get_contents(__DIR__ . '/xcontroller.dat');
|
||||
|
||||
$content = str_replace('User', $model, $content);
|
||||
$content = str_replace('$user', $var, $content);
|
||||
|
||||
Artisan::call('make:request', ['name' => $model.'SaveRequest']);
|
||||
Artisan::call('make:controller', ['name' => 'Admin/' . $model . 'Controller']);
|
||||
|
||||
|
||||
$model_content = file_get_contents(__DIR__.'/../../Models/'.$model.'.php');
|
||||
|
||||
if (!strpos($model_content,'SoftDeletes')){
|
||||
$pattern = '/\/\*\*restore\*\/(.*?)\/\*restore\*\*\//s';
|
||||
$replacement = '';
|
||||
$content = preg_replace($pattern, $replacement, $content);
|
||||
}
|
||||
file_put_contents(__DIR__.'/../../Http/Controllers/Admin/' . $model . 'Controller.php',$content);
|
||||
$this->info('Admin/' . $model . 'Controller created');
|
||||
$this->info( $model.'SaveRequest created');
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\XController;
|
||||
use App\Http\Requests\UserSaveRequest;
|
||||
use App\Models\Access;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helper;
|
||||
use function App\Helpers\hasCreateRoute;
|
||||
|
||||
class UserController extends XController
|
||||
{
|
||||
protected $cols = [];
|
||||
|
||||
protected $searchable = [];
|
||||
|
||||
|
||||
protected const request = UserSaveRequest::class;
|
||||
|
||||
protected $buttons = [
|
||||
'edit' =>
|
||||
['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
|
||||
'show' =>
|
||||
['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
|
||||
'destroy' =>
|
||||
['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
|
||||
];
|
||||
|
||||
public function save($user, $request)
|
||||
{
|
||||
|
||||
$user->save();
|
||||
return $user;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
return view($this->formView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(User $item)
|
||||
{
|
||||
//
|
||||
return view($this->formView, compact('item'));
|
||||
}
|
||||
|
||||
public function bulk(Request $request)
|
||||
{
|
||||
|
||||
// dd($request->all());
|
||||
$data = explode('.', $request->input('action'));
|
||||
$action = $data[0];
|
||||
$ids = $request->input('id');
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
|
||||
self::_MODEL_::destroy($ids);
|
||||
break;
|
||||
/**restore*/
|
||||
case 'restore':
|
||||
$msg = __(':COUNT items restored successfully', ['COUNT' => count($ids)]);
|
||||
foreach ($ids as $id) {
|
||||
self::_MODEL_::withTrashed()->find($id)->restore();
|
||||
}
|
||||
break;
|
||||
/*restore**/
|
||||
default:
|
||||
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
|
||||
}
|
||||
|
||||
return $this->do_bulk($msg, $action, $ids);
|
||||
}
|
||||
|
||||
public function destroy(User $item)
|
||||
{
|
||||
return parent::delete($item);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, User $item)
|
||||
{
|
||||
return $this->bringUp($request, $item);
|
||||
}
|
||||
|
||||
/**restore*/
|
||||
public function restore($item)
|
||||
{
|
||||
return parent::restoreing(User::withTrashed()->where('id', $item)->first());
|
||||
}
|
||||
/*restore**/
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
interface SafeController
|
||||
{
|
||||
//
|
||||
public function createOrUpdate();
|
||||
}
|
Loading…
Reference in New Issue