Documente Academic
Documente Profesional
Documente Cultură
event listeners
+ $table->increments('id');
+ $table->timestamps();
+ $table->string('author');
+ });
//quotelog.php
app/Providers/EventServiceProvider.php
protected $listen = [
- 'App\Events\SomeEvent' => [
- 'App\Listeners\EventListener',
- ],
'App\Events\QuoteCreated' => [
'App\Listeners\CreateLogEntry',
],
];
app/Events/QuoteCreated.php
{
$this->author = $author->name;
app/Listeners/CreateLogEntry.php
$author = $event->author;
$log_entry->author = $author;
$log_entry->save();
//quotecontroller
use App\Events\QuoteCreated;
use Illuminate\Support\Facades\Event;
{ ...
$quote->quote = $quoteText;
$author->quotes()->save($quote);
Event::fire(new QuoteCreated($author));
return redirect()->route('index')->with([
]);
//views/index
<div class="input-group">
</div>
app/Http/Controllers/QuoteController.php
$this->validate($request,[
]);
authors migration
$table->string('email');
//quotecontroller
if(!$author){
$author=new Author();
$author->name = $authorText;
+ $author->email = $request['email'];
$author->save();
}
sending email
//eventserviceprovider
'App\Listeners\SendUserNotification'
//listeners/sendusernotification
$author = $event->author_name;
$email = $event->author_email;
Mail::send(
'email.user_notification',
['name'=>$author],
function($message) use($email,$author) {
$message->from('admin@test.com','Admin');
$message->to($email,$author);
);
//views/email/user_notification.blade.php
app/Events/QuoteCreated.php
- $this->author = $author->name;
+ $this->author_name = $author->name;
+ $this->author_email = $author->email;
app/Listeners/CreateLogEntry.php
- $author = $event->author;
+ $author = $event->author_name;
send attachments
$message->attach('storage/images/logo.jpg');
//authorlog migration
$table->string('author');
/routes
Route::get('/gotemail/{author_name}',[
]);
resources/views/email/callback.blade.php
@extends('layouts.master')
@section('content')
@endsection
//quotecontroller
$author_log->author = $author_name;
$author_log->save();
return view('email.callback',['author'=>$author_name]);
//views/email/user_notification.blade.php
//admin migration
$table->string('name');
$table->string('password');
$table->rememberToken();
//admintableseeder
$admin->name = "admin";
$admin->password = bcrypt("password");
$admin->save();
views/admin/login.blade.php
@extends('layouts.master')
@section('content')
<div class="input-group">
</div>
<div class="input-group">
</div>
<button type="submit">Login</button>
</form>
@endsection
//admincontroller
return view('admin.login');
//routes
Route::get('/admin/login',[
]);
//views/admin/login
@extends('layouts.master')
@section('content')
@if(count($errors) > 0)
<ul>
@foreach($errors->all() as $error)
{{ $error }}
@endforeach
</ul>
</section>
@endif
@if(Session::has('fail'))
{{ Session::get('fail') }}
</section>
@endif
<div class="input-group">
</div>
<div class="input-group">
</div>
<button type="submit">Login</button>
<input type="hidden" name="_token" value=" {{ Session::token() }} "/>
</form>
@endsection
//routes
Route::post('/admin/login',[
]);
Route::get('/admin/dashboard',[
])
admincontroller
$this->validate($request,[
]);
if(!Auth::attempt(['name'=>$request['name'],'password'=> $request['password']])){
return redirect()->route('admin.dashboard');
}
//config/auth
//admincotnroller
$authors = Author::all();
return view('admin.dashboard',['authors'=>$authors]);
//admin model
use Illuminate\Auth\Authenticatable;
use Authenticatable;
// routes
Route::get('/admin/logout',[
]);
//header.blade.php
<a href=" {{ route('admin.login') }} ">Admin</a>
@if(Auth::check())
@endif
//admincontroller
Auth::logout();
return redirect()->route('index');
//admincontroller
if(!Auth::check()){
return redirect()->back();
$authors = Author::all();
return view('admin.admin',['authors'=>$authors]);
Route::get('/admin/dashboard',[
]);
//exceptions/handler.php
return redirect()->route('admin.login');
Route::get('/admin/quotes',function(){
return view('admin.quotes');
})->middleware('auth');
Route::group(['middleware'=>'auth'] , function(){
Route::get('/admin/dashboard',[
]);
Route::get('/admin/logout',[
]);
Route::get('/admin/quotes',function(){
return view('admin.quotes');
/*})->middleware('auth');*/
});
});