Viewing file: SenderController.php (5.09 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Customer;
use App\Http\Controllers\Controller;
use App\Models\Sender;
use Illuminate\Http\Request;
class SenderController extends Controller
{
public function index()
{
return view('customer.sender.index');
}
public function create()
{
$data['domains'] = auth('customer')->user()->domains()->where('dkim_key_verified','yes')->where('spf_key_verified','yes')->where('text_verified','yes')->where('dmarc_key_verified','yes')->get();
return view('customer.sender.create',$data);
}
public function edit(Sender $sender)
{
$data['sender'] = $sender;
$data['domains'] = auth('customer')->user()->domains()->where('dkim_key_verified','yes')->where('spf_key_verified','yes')->where('text_verified','yes')->where('dmarc_key_verified','yes')->get();
return view('customer.sender.edit', $data);
}
public function show(){}
public function store(Request $request)
{
if (config("app.demo")){
return redirect()->back()->withErrors(['message' => trans('admin.app_demo_message')]);
}
$request->validate([
'name' => 'required',
'reply_to' => 'required',
'domain' => 'required',
'from_mail' => 'required|unique:senders|max:191',
]);
if(filter_var($request->from_mail,FILTER_VALIDATE_EMAIL)){
return redirect()->back()->withInput()->withErrors(['message' => 'From email should be username only, not full email address']);
}
$user = auth('customer')->user();
$domain = $user->domains()->where('id',$request->domain)->first();
if ($domain){
if ($domain->dkim_key_verified == 'yes' && $domain->spf_key_verified == 'yes' && $domain->text_verified == 'yes' && $domain->dmarc_key_verified == 'yes'){
$request['domain_id'] = $domain->id;
$request['domain'] = $domain->name;
$user->senders()->create($request->all());
return redirect()->route('customer.sender.index')->with('success', 'Sending sender successfully created');
}else{
return redirect()->back()->with('fail','Domain not verified');
}
}else{
return redirect()->back()->with('fail','Domain not found');
}
}
public function getAll()
{
$senders = auth('customer')->user()->senders()->select(['id', 'name', 'domain_id','from_mail','reply_to']);
return datatables()->of($senders)
->addColumn('from_mail', function ($q) {
return $q->from_mail.'@'.$q->domain->name;
})
->addColumn('action', function ($q) {
return "<a class='btn btn-sm btn-info' href='" . route('customer.sender.edit', [$q]) . "'>Edit</a> " .
'<button class="btn btn-sm btn-danger" data-message="Are you sure you want to delete this sender?"
data-action=' . route('customer.sender.destroy', [$q]) . '
data-input={"_method":"delete"}
data-toggle="modal" data-target="#modal-confirm">Delete</button>';
})
->addColumn('domain_name', function ($q) {
$domain_name = $q->domain->name;
return $domain_name;
})
->rawColumns(['action'])
->toJson();
}
public function update(Sender $sender,Request $request)
{
$request->validate([
'name' => 'required',
'reply_to' => 'required',
'domain' => 'required',
'from_mail' => 'required|max:191|unique:senders,from_mail,' . $sender->id,
]);
if(filter_var($request->from_mail,FILTER_VALIDATE_EMAIL)){
return redirect()->back()->withInput()->withErrors(['message' => 'From email should be username only, not full email address']);
}
$user = auth('customer')->user();
$domain = $user->domains()->where('id',$request->domain)->first();
if ($domain){
if ($domain->dkim_key_verified == 'yes' && $domain->spf_key_verified == 'yes' && $domain->text_verified == 'yes' && $domain->dmarc_key_verified == 'yes'){
$request['domain_id'] = $domain->id;
$request['domain'] = $domain->name;
$sender->update($request->all());
return redirect()->route('customer.sender.index')->with('success', 'Sending sender successfully updated');
}else{
return redirect()->back()->with('fail','Domain not verified');
}
}else{
return redirect()->back()->with('fail','Domain not found');
}
}
public function destroy(Sender $sender)
{
if(auth('customer')->user()->id != $sender->customer_id){
abort(404);
}
$sender->delete();
return back()->with('success', 'Sending sender successfully deleted');
}
}
|