|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Product;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Validation\Rules\In;
|
|
|
|
|
|
|
|
class CustomerController extends Controller
|
|
|
|
{
|
|
|
|
//
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->middleware(function ($request, $next) {
|
|
|
|
|
|
|
|
if (!auth('customer')->check()) {
|
|
|
|
return redirect()->route('client.sign-in');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (\Session::has('locate')) {
|
|
|
|
app()->setLocale(\Session::get('locate'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function profile()
|
|
|
|
{
|
|
|
|
$area = 'customer';
|
|
|
|
$title = __("Profile");
|
|
|
|
$subtitle = 'You information';
|
|
|
|
return view('client.default-list', compact('area', 'title', 'subtitle'));
|
|
|
|
return auth('customer')->user();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'name' => ['required', 'string', 'max:255'],
|
|
|
|
'email' => ['required', 'string', 'email', 'max:255'],
|
|
|
|
'mobile' => ['required', 'string', 'max:255'],
|
|
|
|
'password' => ['nullable', 'string', 'min:8', 'confirmed'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$customer = auth('customer')->user();
|
|
|
|
$customer->name = $request->name;
|
|
|
|
$customer->email = $request->email;
|
|
|
|
$customer->mobile = $request->mobile;
|
|
|
|
if ($request->has('password') && trim($request->input('password')) != '') {
|
|
|
|
$customer->password = bcrypt($request->password);
|
|
|
|
}
|
|
|
|
$customer->save();
|
|
|
|
return redirect()->route('client.profile')->with('message', __('Profile updated successfully'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function invoice(Invoice $invoice)
|
|
|
|
{
|
|
|
|
return $invoice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function ProductFavToggle($slug)
|
|
|
|
{
|
|
|
|
$product = Product::where('slug', $slug)->firstOrFail();
|
|
|
|
|
|
|
|
if (!auth('customer')->check()) {
|
|
|
|
return errors([
|
|
|
|
__("You need to login first"),
|
|
|
|
], 403, __("You need to login first"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auth('customer')->user()->favorites()->where('product_id', $product->id)->count() == 0) {
|
|
|
|
auth('customer')->user()->favorites()->attach($product->id);
|
|
|
|
$message = __('Product added to favorites');
|
|
|
|
$fav = '1';
|
|
|
|
} else {
|
|
|
|
auth('customer')->user()->favorites()->detach($product->id);
|
|
|
|
$message = __('Product removed from favorites');
|
|
|
|
$fav = '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (\request()->ajax()) {
|
|
|
|
return success($fav, $message);
|
|
|
|
} else {
|
|
|
|
return redirect()->back()->with(['message' => $message]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|