migrate to gtea from bistbucket
This commit is contained in:
40
public/restaurant/app/Traits/Authenticatable.php
Normal file
40
public/restaurant/app/Traits/Authenticatable.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Exception;
|
||||
|
||||
trait Authenticatable
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getCurrentUserId(): int
|
||||
{
|
||||
if (app()->runningInConsole()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (! isset(request()->user()->id)) {
|
||||
throw new Exception('You are not authenticated to view this.');
|
||||
}
|
||||
|
||||
return (int) request()->user()->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getCurrentRestaurantId(): int
|
||||
{
|
||||
if (app()->runningInConsole()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (! isset(request()->user()->restaurant_id)) {
|
||||
throw new Exception('You are not authenticated to view this.');
|
||||
}
|
||||
|
||||
return (int) request()->user()->restaurant_id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user