gpt4 book ai didi

php - 如何缩进 Laravel Controller ,查看代码?

转载 作者:可可西里 更新时间:2023-10-31 23:27:52 26 4
gpt4 key购买 nike

我的一个项目需要代码缩进,它有很多 Controller 文件看起来像下面的代码。

所以基本上我想做的是格式化代码,它应该自动完成而无需手动更改每个文件。

Controller 代码

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\URL;
use File;
use Html;
use DB;
use Illuminate\Validation\Rule;
use Illuminate\Support\Str;
use Validator;
use Datatables;
use AppHelper;
use LaraCore;
use Image;
use App\Models\Customer;
use App\Models\_List;
use Carbon;



class CustomerController extends Controller
{

public function validator(array $data, $id = NULL)
{
$email_Rules = explode(',',"required,email,unique");
$email_Rules['unique'] = Rule::unique('customers')->ignore($id);
if(($key = array_search('unique',$email_Rules)) !== false) {
unset($email_Rules[$key]);
}
return Validator::make($data, [
'secret_key' => 'required|min:6|max:10',
'email' => $email_Rules,
'first_name' => 'required|alpha_num',
'city' => 'required',

]
);

}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{


return view('panel.customers.index');
}

public function create()
{
$data = array();
$EmployeeType = _List::where('list_name','=','EmployeeType')->pluck('item_name','id')->all();
$data['EmployeeType'] = $EmployeeType;
$Category = _List::where('list_name','=','Category')->pluck('item_name','id')->all();
$data['Category'] = $Category;
return view('panel.customers.create',$data);
}

public function edit($id,Request $request)
{
$data = array();
$Dates = array();
$customers = Customer::findOrFail($id);
$data['customers'] = $customers;



$EmployeeType = _List::where('list_name','=','EmployeeType')->pluck('item_name','id')->all();
$data['EmployeeType'] = $EmployeeType;

$preference= explode(',',$customers->preference);
$customers->preference = $preference;

$Category = _List::where('list_name','=','Category')->pluck('item_name','id')->all();
$data['Category'] = $Category;




if($customers->ready!=''){
$ready= explode(',',$customers->ready);
$customers->ready = $ready;
}

if($customers->approved!=''){
$approved= explode(',',$customers->approved);
$customers->approved = $approved;
}





$Name = explode(',','start_date,end_date');
$Dates[0] = new Carbon($customers->$Name[0]);
$Dates[1] = new Carbon($customers->$Name[1]);
$data['start_dateend_date'] = $Dates[0]->format('m/d/Y').' - '.$Dates[1]->format('m/d/Y') ;

return view('panel.customers.create',$data);
}

public function store(Request $request,$id="")
{
$this->validator($request->all(),$request->id)->validate();
if($request->id == null || $request->id == ""){
$inputs = $request->all();

if($request->has('secret_key')){
$secret_key = bcrypt($request->secret_key);
$inputs['secret_key'] = $secret_key;
}



if($request->has('preference')){
$preference = implode(',',$request->preference);
$inputs['preference'] = $preference;
}







if($request->has('ready')){
$ready = implode(',',$request->ready);
$inputs['ready'] = $ready;
}else{
$inputs['ready'] = "";
}







if($request->has('start_date,end_date')){
$Dates = explode('-',$request->input('start_date,end_date'));
$Name = explode(',','start_date,end_date');
$inputs[''.$Name[0]] = $Dates[0];
$Dates[0] = new Carbon($Dates[0]);
$Dates[1] = new Carbon($Dates[1]);
$inputs[''.$Name[0]] = $Dates[0]->format('Y-m-d');
$inputs[''.$Name[1]] = $Dates[1]->format('Y-m-d');
//dd($inputs);
}


foreach($request->files as $key_file => $value_file){
$nameArr = explode(',',$key_file);
$file = $value_file;
$destinationPath = 'public/uploads/customers';
\File::makeDirectory($destinationPath,0775,true,true);
$name = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$encrypted_name = md5(uniqid().time()).".".$extension;
$file->move($destinationPath,$encrypted_name);
$inputs[''.$nameArr[0]] = $name;
$inputs[''.$nameArr[1]] = $encrypted_name;
}

Customer::create($inputs);
return redirect()->route('customers.index')->with('success',"Customer Saved successfully");
}
else{
$customers = Customer::where(['id'=>$request->input('id')])->first();
$inputs = $request->except('_token');

if($request->has('secret_key')){
$secret_key = bcrypt($request->secret_key);
$inputs['secret_key'] = $secret_key;
}



if($request->has('preference')){
$preference = implode(',',$request->preference);
$inputs['preference'] = $preference;
}







if($request->has('ready')){
$ready = implode(',',$request->ready);
$inputs['ready'] = $ready;
}







if($request->has('start_date,end_date')){
$Dates = explode('-',$request->input('start_date,end_date'));
$Name = explode(',','start_date,end_date');
$inputs[''.$Name[0]] = $Dates[0];
$Dates[0] = new Carbon($Dates[0]);
$Dates[1] = new Carbon($Dates[1]);
$inputs[''.$Name[0]] = $Dates[0]->format('Y-m-d');
$inputs[''.$Name[1]] = $Dates[1]->format('Y-m-d');
//dd($inputs);
}

foreach($request->files as $key_file => $value_file){
$destinationPath = 'public/uploads/customers';
\File::makeDirectory($destinationPath,0775,true,true);
$nameArr = explode(',',$key_file);
$OldFile = $customers->$nameArr[1];
if($OldFile!=''){
$OldFile = $destinationPath.'/'.$OldFile;
if(\File::exists($OldFile)){
\File::delete($OldFile);
}
}
$file = $value_file;
$name = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$encrypted_name = md5(uniqid().time()).".".$extension;
$file->move($destinationPath,$encrypted_name);
$inputs[''.$nameArr[0]] = $name;
$inputs[''.$nameArr[1]] = $encrypted_name;
$SavedFile = $destinationPath.$encrypted_name;
}
$customers->update($inputs);
return redirect()->route('customers.index')->with('success',"Customer Saved successfully");
}

}

public function listCustomer(Request $request)
{
$customers = Customer::all();

$datatables = Datatables::of($customers)
->addColumn('actions', function($customers){
$html = '';

$html .= '<a href="'.route('customers.edit', ['customer' => $customers->id]).'" class="btn show-tooltip btn-action" name="" data-id="'.$customers->id.'" title="Edit"><i class="fa fa-edit"></i></a>';

$html .= '<a href="javascript:void(0)" data-toggle="modal" data-target="#delete_customer_modal" class="btn show-tooltip btn-action" name="" data-id="'.$customers->id.'" data-action="'.route('customers.destroy', ['customer' => $customers->id]).'" title="Delete"><i class="fa fa-trash"></i></a>';
return $html;
})
->setRowId('id');

return $datatables->make();
}

public function destroy($id)
{
$customer = Customer::find($id);
$customer->delete();

return response()->json(array(
"status" => "success",
"message" => "Customer Deleted Successfully",
));
}
}

最佳答案

也许您可以在您创建的文件上调用 php 美化程序? http://pear.php.net/package/PHP_Beautifier/

注意:您可以使用 exec 调用命令

exec("php_beautifier $filename $filename");

关于php - 如何缩进 Laravel Controller ,查看代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43519915/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com