Viewing file: WeightController.php (4.16 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Customer;
use App\Http\Controllers\Controller; use App\Models\Weight; use Illuminate\Http\Request;
class WeightController extends Controller {
public function index() { $user = auth()->user(); $data['weekDates']=getLastNDays(30); $data['weights'] = Weight::where('customer_id',$user->id)->pluck('weight'); return view('customer.weight.index',$data); }
public function getAll(Request $request) { $weights = Weight::where('customer_id',auth()->user()->id)->orderByDesc('created_at'); return datatables()->of($weights)
->addColumn('profile', function (Weight $q) { $img = asset('uploads/' . $q->image) ; $profile = '<a href="#" class="customer-img-show" data-img="'.$img.'"> <div class="profile-img-sec"> <img src="' . $img . '" height="40" width="45"> </div>
</a>';
return $profile; }) ->addColumn('weight', function (Weight $q) {
$weight = $q->weight . ' kg'; return $weight; }) ->addColumn('created_at', function (Weight $q) { $created_at=formatDate($q->created_at); return $created_at; })
->addColumn('action', function (Weight $q) { return "<a class='btn btn-sm btn-info' href='" . route('customer.weight.edit', [$q->id]) . "'>Edit</a> " . '<button class="btn btn-sm btn-danger" data-message="Are you sure you want to delete this Weight?" data-action=' . route('customer.weight.destroy', [$q]) . ' data-input={"_method":"delete"} data-toggle="modal" data-target="#modal-confirm">Delete</button>'; }) ->rawColumns(['action', 'profile','created_at']) ->toJson(); }
public function create() {
return view('customer.weight.create'); }
public function store(Request $request) {
$request->validate([ 'weight' => 'required', 'customer_image' => 'required' ]);
$profile_pic = 'default_profile.png'; if ($request->hasFile('customer_image')) { $file = $request->file('customer_image'); $imageName = time() . '.' . $file->getClientOriginalExtension(); $file->move(public_path('/uploads/'), $imageName); $profile_pic = $imageName; }
$weight = new Weight(); $weight->customer_id = auth()->user()->id; $customer_weight = preg_replace("/[^0-9\.]/", '', $request->weight); $weight->weight = $customer_weight; $weight->image = $profile_pic; $weight->save();
return redirect()->route('customer.weight.index')->with('success', 'Weight successfully created'); }
public function edit($weight) { $weight = Weight::findOrFail($weight);
$data['weight'] = $weight;
return view('customer.weight.edit', $data); }
public function update($weight, Request $request) { $request->validate([ 'weight' => 'required', ]);
$weights = Weight::findOrFail($weight);
if ($request->hasFile('customer_image')) { $file = $request->file('customer_image'); $imageName = time() . '.' . $file->getClientOriginalExtension(); $file->move(public_path('/uploads/'), $imageName); $weights->image = $imageName;
}
$weights->customer_id = auth()->user()->id; $customer_weight = preg_replace("/[^0-9\.]/", '', $request->weight); $weights->weight = $customer_weight; $weights->save();
return redirect()->route('customer.weight.index')->with('success', 'Weight successfully update'); }
public function destroy($weight) { $weight = Weight::findOrFail($weight); $weight->delete();
return redirect()->route('customer.weight.index')->with('success', 'Weight successfully Deleted'); }
}
|