migrate to gtea from bistbucket
This commit is contained in:
52
public/restaurant/app/Helper/RestaurantHelper.php
Normal file
52
public/restaurant/app/Helper/RestaurantHelper.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user