53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Helper;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class RestaurantHelper
|
|
{
|
|
/**
|
|
* Get restaurant ID based on the domain.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public static function getRestaurantIdByDomain(string $domain)
|
|
{
|
|
// Check if domain is provided
|
|
if (empty($domain)) {
|
|
return [
|
|
'error' => 'Domain is required.',
|
|
'status' => false,
|
|
];
|
|
}
|
|
|
|
// Check if domain format is valid (e.g., example.com)
|
|
if (! filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
|
|
return [
|
|
'error' => 'Invalid domain format.',
|
|
'status' => false,
|
|
];
|
|
}
|
|
|
|
// Fetch the restaurant based on the domain
|
|
$restaurant = DB::table('restaurants')
|
|
->where('domain', $domain)
|
|
->select('id')
|
|
->first();
|
|
|
|
// If no matching restaurant is found
|
|
if (! $restaurant) {
|
|
return [
|
|
'error' => 'Restaurant not found for the provided domain.',
|
|
'status' => false,
|
|
];
|
|
}
|
|
|
|
// Return the restaurant ID
|
|
return [
|
|
'restaurant_id' => $restaurant->id,
|
|
'status' => true,
|
|
];
|
|
}
|
|
}
|