added api macros to request
This commit is contained in:
parent
9269b93e3d
commit
f7bc89806c
@ -90,7 +90,7 @@ abstract class Model extends Eloquent
|
|||||||
|
|
||||||
$query->usingSearchString($search)->sortable($sort);
|
$query->usingSearchString($search)->sortable($sort);
|
||||||
|
|
||||||
if ($request->expectsJson()) {
|
if ($request->expectsJson() && $request->isNotApi()) {
|
||||||
return $query->get();
|
return $query->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\View\Factory as ViewFactory;
|
use Illuminate\View\Factory as ViewFactory;
|
||||||
@ -15,6 +16,14 @@ class Macro extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
|
Request::macro('isApi', function () {
|
||||||
|
return $this->is(config('api.subtype') . '/*');
|
||||||
|
});
|
||||||
|
|
||||||
|
Request::macro('isNotApi', function () {
|
||||||
|
return !$this->isApi();
|
||||||
|
});
|
||||||
|
|
||||||
Str::macro('filename', function ($string, $separator = '-') {
|
Str::macro('filename', function ($string, $separator = '-') {
|
||||||
// Replace @ with the word 'at'
|
// Replace @ with the word 'at'
|
||||||
$string = str_replace('@', $separator.'at'.$separator, $string);
|
$string = str_replace('@', $separator.'at'.$separator, $string);
|
||||||
@ -34,6 +43,7 @@ class Macro extends ServiceProvider
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ trait Permissions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = request()->is('api/*') ? request()->segment(2) : '';
|
$table = request()->isApi() ? request()->segment(2) : '';
|
||||||
|
|
||||||
// Fire event to find the proper controller for common API endpoints
|
// Fire event to find the proper controller for common API endpoints
|
||||||
if (in_array($table, ['contacts', 'documents', 'transactions'])) {
|
if (in_array($table, ['contacts', 'documents', 'transactions'])) {
|
||||||
|
@ -13,7 +13,7 @@ if (!function_exists('user')) {
|
|||||||
function user()
|
function user()
|
||||||
{
|
{
|
||||||
// Get user from api/web
|
// Get user from api/web
|
||||||
if (request()->is('api/*')) {
|
if (request()->isApi()) {
|
||||||
$user = app('Dingo\Api\Auth\Auth')->user();
|
$user = app('Dingo\Api\Auth\Auth')->user();
|
||||||
} else {
|
} else {
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
@ -15,7 +15,7 @@ return [
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'paths' => ['api/*'],
|
'paths' => [env('API_SUBTYPE', 'api') . '/*'],
|
||||||
|
|
||||||
'allowed_methods' => ['*'],
|
'allowed_methods' => ['*'],
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user