Created
November 2, 2016 03:29
-
-
Save cpereiraweb/1a709c6078903a659c91a61f44256980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace SnPortal\Providers; | |
use SnPortal\Models\Client; | |
use SnPortal\Observers\ClientObserver; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Client::observe(ClientObserver::class); | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace SnPortal\Observers; | |
use SnPortal\Models\Client; | |
class ClientObserver | |
{ | |
/** | |
* Listen to the Client creating event. | |
* | |
* @param Client $client | |
* @return void | |
*/ | |
public function creating(Client $client) | |
{ | |
$client->created_by = (App::runningInConsole()?1:\Auth::user()->id); // Se estiver rodando via artisan, atribui 1 | |
$client->updated_by = (App::runningInConsole()?1:\Auth::user()->id); // Se estiver rodando via artisan, atribui 1 | |
} | |
/** | |
* Listen to the Client updating event. | |
* | |
* @param Client $client | |
* @return void | |
*/ | |
public function updating(Client $client) | |
{ | |
$client->updated_by = (App::runningInConsole()?1:\Auth::user()->id); // Se estiver rodando via artisan, atribui 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment