0
我想在我的模型中創建審計線索。我已經通過Composer安裝了owen-it/laravel-auditing軟件包。我的問題是,我怎樣才能在我的模型或控制器中實現它。請參閱我的代碼,瞭解下面的控制器和型號。由於如何在模型中實現owen-it/laravel-auditing
我的控制器:
<?php
namespace App\Http\Controllers;
use App\Events\Test;
use App\Letter;
use App\Notifications\LetterNotification;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Validator;
class LetterController extends Controller
{
public function viewLetter()
{
return view('welcome');
}
/**
* Saves email into database
*
* @param array $data
* @return Letter
*/
protected function create(array $data)
{
$letter = Letter::create([
'email' => $data['email']
]);
$this->letterNotify($letter);
return $letter;
}
/**
* Validates email
*/
public function createLetter(Request $request)
{
$this->validate($request,[
'email' => 'required|email|max:255|unique:letters'
],[
'email.required' => 'Email is required.',
'email.unique' => 'Already registered.',
'email.email' => 'Please put a valid Email address'
]);
$this->create($request->all());
return redirect('/')->with('info','You are now registered.');
}
protected function letterNotify($letter)
{`enter code here`
Notification::send($letter, new LetterNotification($letter));
}
}
對於我的模型:
<?php
namespace App;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class Letter extends Model implements AuditableContract
{
use Notifiable;
use Auditable;
protected $fillable = ['email'];
protected $table = 'letters';
}
您提交的代碼看起來很好。請解釋什麼不起作用,或者你期望看到/發生什麼。 [documentation](http://www.laravel-auditing.com/docs/4.0)應該有你需要的一切。 –
@QuetzyGarcia只想問一下這個laravel-auditing包是否可以應用在默認包'Auth'中? – sack
你的問題不清楚。你想知道[用戶解析器](http://www.laravel-auditing.com/docs/4.0/general-settings)是否可以使用不同的包而不是'Auth'(例如''Sentinel') ? –