File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 66namespace Javaabu \Helpers \Traits ;
77
88use App \Models \User ;
9+ use Illuminate \Contracts \Auth \Access \Authorizable ;
910
1011trait Publishable
1112{
@@ -127,6 +128,11 @@ public function getRejectedKey()
127128 return $ status_class ::REJECTED ;
128129 }
129130
131+ public function canPublish (Authorizable $ user ): bool
132+ {
133+ return $ user ->can ('publish ' , static ::class);
134+ }
135+
130136 /**
131137 * Update the status
132138 *
@@ -136,12 +142,14 @@ public function getRejectedKey()
136142 */
137143 public function updateStatus ($ status , $ publish = false )
138144 {
145+ $ user = auth ()->user ();
146+
139147 //first check if requesting for publishing
140148 if ($ publish || $ status == $ this ->getPublishedKey ()) {
141149 $ this ->publish ();
142150 } elseif ($ status == $ this ->getRejectedKey ()) {
143151 $ this ->reject ();
144- } elseif ($ status && auth ()-> check () && auth ()-> user ()-> can ( ' publish ' , static ::class )) {
152+ } elseif ($ status && $ user && $ this -> canPublish ( $ user )) {
145153 $ this ->status = $ status ;
146154 } else {
147155 $ this ->draft ();
You can’t perform that action at this time.
0 commit comments