芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/bit-alphas-ltd.com/user/project/app/Http/Controllers/Admin/TeamController.php
middleware('auth:admin'); } public function datatables() { $datas = Team::orderBy('id','desc')->get(); return Datatables::of($datas) ->editColumn('photo', function(Team $data) { $photo = $data->photo ? url('assets/images/'.$data->photo):url('assets/images/noimage.png'); return '
'; }) ->addColumn('action', function(Team $data) { return '
'.'Actions' .'
'.__("Edit").'
'.__("Delete").'
'; }) ->rawColumns(['photo', 'action']) ->toJson(); //--- Returning Json Data To Client Side } public function index() { return view('admin.teams.index'); } public function create() { return view('admin.teams.create'); } public function store(Request $request) { $rules = [ 'photo' => 'required|mimes:jpeg,jpg,png,svg', ]; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return response()->json(array('errors' => $validator->getMessageBag()->toArray())); } $data = new Team(); $input = $request->all(); if ($file = $request->file('photo')) { $name = Str::random(8).time().'.'.$file->getClientOriginalExtension(); $file->move('assets/images',$name); $input['photo'] = $name; } $data->fill($input)->save(); $msg = 'New Data Added Successfully.'.'
View Lists
'; return response()->json($msg); } public function edit($id) { $data = Team::findOrFail($id); return view('admin.teams.edit',compact('data')); } public function update(Request $request, $id) { $rules = [ 'photo' => 'mimes:jpeg,jpg,png,svg', ]; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return response()->json(array('errors' => $validator->getMessageBag()->toArray())); } $data = Team::findOrFail($id); $input = $request->all(); if ($file = $request->file('photo')) { $name = Str::random(8).time().'.'.$file->getClientOriginalExtension(); $file->move('assets/images',$name); @unlink('assets/images/'.$data->photo); $input['photo'] = $name; } $data->update($input); $msg = 'Data Updated Successfully.'.'
View Lists
'; return response()->json($msg); } public function destroy($id) { $data = Team::findOrFail($id); @unlink('assets/images/'.$data->photo); $data->delete(); $msg = 'Data Deleted Successfully.'; return response()->json($msg); } }