Skip to content

Commit cc03c75

Browse files
committed
feat: added support for auth functions
1 parent e971c95 commit cc03c75

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/Request.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @author Michael Darko
1414
* @since 1.0.0
15-
* @version 2.0
15+
* @version 2.3.0
1616
*/
1717
class Request
1818
{
@@ -316,13 +316,40 @@ public static function validate(array $rules)
316316
return \Leaf\Form::validate(static::body(false), $rules);
317317
}
318318

319+
/**
320+
* @return \Leaf\Auth
321+
*/
322+
protected static function auth()
323+
{
324+
if (!class_exists('\Leaf\Auth')) {
325+
throw new \Exception("You need to install the leaf-auth package to use the auth helper");
326+
}
327+
328+
if (!(\Leaf\Config::get('auth.instance'))) {
329+
\Leaf\Config::set('auth.instance', new \Leaf\Auth());
330+
}
331+
332+
return \Leaf\Config::get('auth.instance');
333+
}
334+
335+
/**
336+
* Get the authenticated user
337+
*/
338+
public static function user()
339+
{
340+
return static::auth()->user();
341+
}
342+
319343
/**
320344
* Handle errors from validation
321345
* @return array
322346
*/
323347
public static function errors()
324348
{
325-
return \Leaf\Form::errors();
349+
return array_merge(
350+
\Leaf\Form::errors(),
351+
static::auth()->errors()
352+
);
326353
}
327354

328355
/**

0 commit comments

Comments
 (0)