initial commit

This commit is contained in:
2025-11-11 14:55:29 +07:00
commit 7c17aa7843
2490 changed files with 606138 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers\Helpers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use DateTime;
use Exception;
use File;
use Redirect;
use Str;
use Storage;
class CkEditorHelperController extends Controller
{
public function __construct()
{
}
public function upload(Request $request)
{
if ($request->hasFile('upload')) {
$originName = $request->file('upload')->getClientOriginalName();
$fileName = pathinfo($originName, PATHINFO_FILENAME);
$extension = $request->file('upload')->getClientOriginalExtension();
$fileName = $fileName . '_' . time() . '.' . $extension;
$request->file('upload')->move(public_path('/uploads/ck-editor/'), $fileName);
$url = asset('/uploads/ck-editor/' . $fileName);
return response()->json(['fileName' => $fileName, 'uploaded' => 1, 'url' => $url]);
}
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Http\Controllers\Helpers;
use Illuminate\Routing\Controller;
use Mail;
class EmailHelperController extends Controller
{
public function __construct()
{
}
public function sendEmailForgotPassword($emailTo, $token)
{
// subject
$subject = 'Forgot Password: The Greater Chiangmai : Has Sent You a Message! No reply This email';
$details = [
'email' => $emailTo,
'link' => url('reset-password/' . $token),
];
Mail::send('emails.forgot-password', $details, function ($message) use ($subject, $details) {
$message->to($details['email'])
->subject($subject);
});
}
public function sendEmailResetPassword($emailTo, $newPassword)
{
// subject
$subject = 'Reset Password: The Greater Chiangmai : Has Sent You a Message! No reply This email';
$details = [
'email' => $emailTo,
'password' => $newPassword,
];
Mail::send('emails.reset-password', $details, function ($message) use ($subject, $details) {
$message->to($details['email'])
->subject($subject);
});
}
public function sendEmailCancelBooking($details)
{
// subject
$subject = 'Cancel Booking: The Greater Chiangmai : Has Sent You a Message! No reply This email';
Mail::send('emails.cancel-booking', $details, function ($message) use ($subject, $details) {
$message->to($details['email'])
->subject($subject);
});
}
public function sendEmailApproveBooking($details)
{
// subject
$subject = 'Approve Booking: The Greater Chiangmai : Has Sent You a Message! No reply This email';
Mail::send('emails.approve-booking', $details, function ($message) use ($subject, $details) {
$message->to($details['email'])
->subject($subject);
});
}
}

View File

@@ -0,0 +1,140 @@
<?php
namespace App\Http\Controllers\Helpers;
use App\Http\DataAccess\UserDataAccess;
use Illuminate\Routing\Controller;
class EmailPhpHelperController extends Controller
{
public function __construct()
{
}
public function sendEmailContact($name, $phone, $email, $comment)
{
$mailSender = env('MAIL_SENDER');
$mailReceiver = env('MAIL_RECEIVER');
// subject
$subject = 'Contact: The Greater Chiangmai : Has Sent You a Message! No reply This email';
// message
$message = '
<!DOCTYPE html>
<html>
<head>
<title> The Greater Chiangmai.com </title>
</head>
<body>
<h3>Hi, ' . 'The Greater Chiangmai' . ' ,</h3>
<p> You have new contact from Contact page, please see the detail below:</p>
<p> Name: ' . $name . ' </p>
<p> Phone: ' . $phone . '</p>
<p> อีเมล: ' . $email . '</p>
<p> ข้อความ: ' . $comment . '</p>
<br/>
<br/>
<p>Thanks,</p>
<p><a href="https://www.The Greater Chiangmai.com/">The Greater Chiangmai</a></p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=utf-8' . "\r\n";
// Additional headers
$headers .= 'From:' . $mailSender . "\r\n";
$headers .= "Reply-To:" . $mailSender . "\r\n";
$headers .= "Return-Path:" . $mailSender . "\r\n";
// Mail it
mail($mailReceiver, $subject, $message, $headers);
}
public function sendEmailForgotPassword($emailTo, $token)
{
$mailSender = env('MAIL_SENDER');
// subject
$subject = 'Forgot Password: The Greater Chiangmai : Has Sent You a Message! No reply This email';
$link = url('reset-password/' . $token);
// message
$message = '
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3>สวัสดี, ' . $emailTo . ' ,</h3>
<p>เราได้รับคำขอให้รีเซ็ตรหัสผ่านสำหรับบัญชีของคุณ: ' . $emailTo . '</p>
<p><a href="' . $link . '">' . $link . '</a> </p>
<br/>
<p>Thanks,</p>
<br/>
<p><a href="https://www.The Greater Chiangmai.com/">Thai Tourism Volunteers</a></p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From:' . $mailSender . "\r\n";
// Mail it
mail($emailTo, $subject, $message, $headers);
}
public function sendEmailResetPassword($emailTo, $newPassword)
{
$mailSender = env('MAIL_SENDER');
// subject
$subject = 'Reset Password: The Greater Chiangmai : Has Sent You a Message! No reply This email';
// message
$message = '
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3>สวัสดี, ' . $emailTo . ' ,</h3>
<p>คุณรีเซ็ตรหัสผ่านสำเร็จแล้ว</p>
<p>รหัสผ่านใหม่ของคุณคือ: ' . $newPassword . '</p>
<br/>
<p>Thanks,</p>
<p><a href="https://www.The Greater Chiangmaimanmanmanman.com/">The Greater Chiangmai</a></p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=utf-8' . "\r\n";
// Additional headers
$headers .= 'From:' . $mailSender . "\r\n";
// Mail it
mail($emailTo, $subject, $message, $headers);
}
}

View File

@@ -0,0 +1,286 @@
<?php
namespace App\Http\Controllers\Helpers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use DateTime;
use Exception;
use File;
use Redirect;
use Str;
use Storage;
class FileHelperController extends Controller
{
private $IMAGE_TYPE_JPEG;
private $IMAGE_TYPE_JPG;
private $IMAGE_TYPE_PNG;
private $PDF_TYPE;
private $DOC_TYPE;
private $DOCX_TYPE;
private $XLS_TYPE;
private $XLSX_TYPE;
public function __construct()
{
$this->IMAGE_TYPE_JPEG = "jpeg";
$this->IMAGE_TYPE_JPG = 'jpg';
$this->IMAGE_TYPE_PNG = 'png';
$this->PDF_TYPE = "pdf";
$this->DOC_TYPE = 'doc';
$this->DOCX_TYPE = 'docx';
$this->XLS_TYPE = 'xls';
$this->XLSX_TYPE = 'xlsx';
}
/* ================== Global ================== */
public function checkImageType($imageType)
{
return strtolower($imageType) != $this->IMAGE_TYPE_JPEG && strtolower($imageType) != $this->IMAGE_TYPE_JPG && strtolower($imageType) != $this->IMAGE_TYPE_PNG;
}
public function checkMixType($fileType)
{
return strtolower($fileType) != $this->IMAGE_TYPE_JPEG &&
strtolower($fileType) != $this->IMAGE_TYPE_JPG &&
strtolower($fileType) != $this->IMAGE_TYPE_PNG &&
strtolower($fileType) != $this->PDF_TYPE &&
strtolower($fileType) != $this->DOC_TYPE &&
strtolower($fileType) != $this->DOCX_TYPE &&
strtolower($fileType) != $this->XLS_TYPE &&
strtolower($fileType) != $this->XLSX_TYPE;
}
public function checkImageSize($fileSize)
{
$customFileSize = 20; // able to change here: //Your file size is bigger than 20mb please upload file again
$limitMaxFileSize = 1024 * 1024 * $customFileSize;
return $fileSize > $limitMaxFileSize;
}
public function checkFileType($fileType)
{
return strtolower($fileType) != $this->PDF_TYPE &&
strtolower($fileType) != $this->DOC_TYPE &&
strtolower($fileType) != $this->DOCX_TYPE &&
strtolower($fileType) != $this->XLS_TYPE &&
strtolower($fileType) != $this->XLSX_TYPE;
}
public function checkFileTypePdfOnly($fileType)
{
return $fileType != $this->PDF_TYPE;
}
public function checkFileSize($fileSize)
{
$customFileSize = 20; // able to change here: //Your file size is bigger than 20mb please upload file again
$limitMaxFileSize = 1024 * 1024 * $customFileSize;
return $fileSize > $limitMaxFileSize;
}
public function checkFileSize3MB($fileSize)
{
$customFileSize = 3; // able to change here: //Your file size is bigger than 3mb please upload file again
$limitMaxFileSize = 1024 * 1024 * $customFileSize;
return $fileSize > $limitMaxFileSize;
}
public function checkFileSize5MB($fileSize)
{
$customFileSize = 5; // able to change here: //Your file size is bigger than 3mb please upload file again
$limitMaxFileSize = 1024 * 1024 * $customFileSize;
return $fileSize > $limitMaxFileSize;
}
/* ================== CK Editor ================== */
public function uploadImageCkEditor(Request $request)
{
$image = $request->file('upload');
$url = $this->uploadImg($image);
$funcNum = $_GET['CKEditorFuncNum'];
if ($url == 'errors') {
return "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '" . url($url) . "', 'Error file is large.')</script>";
} else {
return "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '" . url($url) . "', '')</script>";
}
}
public function uploadImg($file)
{
try {
$folder = "uploads/ckeditor/images";
if (File::isDirectory($folder) == false) {
Storage::makeDirectory($folder, 0777, true);
}
$name = $file->getClientOriginalName();
$ext = pathinfo($name, PATHINFO_EXTENSION);
$rdStr = rand();
$date = new DateTime();
$format = $date->format('Ymdhms');
$newName = $format . '_' . $rdStr . '.' . $ext;
$file->move($folder, $newName);
return $folder . "/" . $newName;
} catch (Exception $e) {
return 'errors';
}
}
public function mimeContentTypeFile($type)
{
$typeLower = strtolower($type);
if ($typeLower === 'pdf') {
return 'application/pdf';
} else if ($typeLower === 'xls' || $typeLower === 'xlsx') {
return 'application/octet-stream';
} else if ($typeLower === 'doc' || $typeLower === 'docx') {
return 'application/octet-stream';
} else {
return 'jpg';
}
}
public function mimeContentTypeImage($type)
{
$typeLower = strtolower($type);
if ($typeLower === 'png') {
return 'image/png';
} else if ($typeLower === 'jpg') {
return 'image/jpeg';
} else if ($typeLower === 'jpeg') {
return 'image/jpeg';
} else {
return 'image/jpeg';
}
}
/*
public function uploadImageCkEditorOld($file)
{
try {
$folder = "uploads/files/ckeditor/images";
$name = $file->getClientOriginalName();
$ext = pathinfo($name, PATHINFO_EXTENSION);
$rdStr = Uuid::generate();
$date = new DateTime();
$format = $date->format('Ymdhms');
$newName = $format . '_' . $rdStr . '.' . $ext;
$file->move($folder, $newName);
return $folder . "/" . $newName;
} catch (\Exception $e) {
return 'errors';
}
}
*/
}
/* File Types */
//[
// '3gp' => 'video/3gpp',
// '7z' => 'application/x-7z-compressed',
// 'aac' => 'audio/x-aac',
// 'ai' => 'application/postscript',
// 'aif' => 'audio/x-aiff',
// 'asc' => 'text/plain',
// 'asf' => 'video/x-ms-asf',
// 'atom' => 'application/atom+xml',
// 'avi' => 'video/x-msvideo',
// 'bmp' => 'image/bmp',
// 'bz2' => 'application/x-bzip2',
// 'cer' => 'application/pkix-cert',
// 'crl' => 'application/pkix-crl',
// 'crt' => 'application/x-x509-ca-cert',
// 'css' => 'text/css',
// 'csv' => 'text/csv',
// 'cu' => 'application/cu-seeme',
// 'deb' => 'application/x-debian-package',
// 'doc' => 'application/msword',
// 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
// 'dvi' => 'application/x-dvi',
// 'eot' => 'application/vnd.ms-fontobject',
// 'eps' => 'application/postscript',
// 'epub' => 'application/epub+zip',
// 'etx' => 'text/x-setext',
// 'flac' => 'audio/flac',
// 'flv' => 'video/x-flv',
// 'gif' => 'image/gif',
// 'gz' => 'application/gzip',
// 'htm' => 'text/html',
// 'html' => 'text/html',
// 'ico' => 'image/x-icon',
// 'ics' => 'text/calendar',
// 'ini' => 'text/plain',
// 'iso' => 'application/x-iso9660-image',
// 'jar' => 'application/java-archive',
// 'jpe' => 'image/jpeg',
// 'jpeg' => 'image/jpeg',
// 'jpg' => 'image/jpeg',
// 'js' => 'text/javascript',
// 'json' => 'application/json',
// 'latex' => 'application/x-latex',
// 'log' => 'text/plain',
// 'm4a' => 'audio/mp4',
// 'm4v' => 'video/mp4',
// 'mid' => 'audio/midi',
// 'midi' => 'audio/midi',
// 'mov' => 'video/quicktime',
// 'mkv' => 'video/x-matroska',
// 'mp3' => 'audio/mpeg',
// 'mp4' => 'video/mp4',
// 'mp4a' => 'audio/mp4',
// 'mp4v' => 'video/mp4',
// 'mpe' => 'video/mpeg',
// 'mpeg' => 'video/mpeg',
// 'mpg' => 'video/mpeg',
// 'mpg4' => 'video/mp4',
// 'oga' => 'audio/ogg',
// 'ogg' => 'audio/ogg',
// 'ogv' => 'video/ogg',
// 'ogx' => 'application/ogg',
// 'pbm' => 'image/x-portable-bitmap',
// 'pdf' => 'application/pdf',
// 'pgm' => 'image/x-portable-graymap',
// 'png' => 'image/png',
// 'pnm' => 'image/x-portable-anymap',
// 'ppm' => 'image/x-portable-pixmap',
// 'ppt' => 'application/vnd.ms-powerpoint',
// 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
// 'ps' => 'application/postscript',
// 'qt' => 'video/quicktime',
// 'rar' => 'application/x-rar-compressed',
// 'ras' => 'image/x-cmu-raster',
// 'rss' => 'application/rss+xml',
// 'rtf' => 'application/rtf',
// 'sgm' => 'text/sgml',
// 'sgml' => 'text/sgml',
// 'svg' => 'image/svg+xml',
// 'swf' => 'application/x-shockwave-flash',
// 'tar' => 'application/x-tar',
// 'tif' => 'image/tiff',
// 'tiff' => 'image/tiff',
// 'torrent' => 'application/x-bittorrent',
// 'ttf' => 'application/x-font-ttf',
// 'txt' => 'text/plain',
// 'wav' => 'audio/x-wav',
// 'webm' => 'video/webm',
// 'webp' => 'image/webp',
// 'wma' => 'audio/x-ms-wma',
// 'wmv' => 'video/x-ms-wmv',
// 'woff' => 'application/x-font-woff',
// 'wsdl' => 'application/wsdl+xml',
// 'xbm' => 'image/x-xbitmap',
// 'xls' => 'application/vnd.ms-excel',
// 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
// 'xml' => 'application/xml',
// 'xpm' => 'image/x-xpixmap',
// 'xwd' => 'image/x-xwindowdump',
// 'yaml' => 'text/yaml',
// 'yml' => 'text/yaml',
// 'zip' => 'application/zip',
//];

View File

@@ -0,0 +1,317 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller;
use App\Models\SubCategoryModel;
use App\Models\ArticleModel;
use Illuminate\Http\Request;
use Redirect;
class HomeController extends Controller
{
public function index()
{
$articleCm = ArticleModel::where('active', 1)
->where('category_id', 1)
->limit(4)
->orderBy('id', 'DESC')
->get();
$articleWhereElse = ArticleModel::where('active', 1)
->where('category_id', 2)
->limit(4)
->orderBy('id', 'DESC')
->get();
$lang = 'index-en';
if (session()->get('locale') == 'th') {
$lang = 'index';
} else {
$lang = 'index-en';
}
return view($lang)
->with('itemView', $articleCm)
->with('itemViewWhereElse', $articleWhereElse);
}
public function about()
{
$lang = 'about/index-en';
if (session()->get('locale') == 'th') {
$lang = 'about/index';
} else {
$lang = 'about/index-en';
}
return view($lang);
}
public function privacyPolicy()
{
$lang = 'about/index-en';
if (session()->get('locale') == 'th') {
$lang = 'privacy-policy/index';
} else {
$lang = 'privacy-policy/index-en';
}
return view($lang);
}
public function category()
{
$data["sub_category"] = [];
$data["count_article"] = 0;
$subCategoryList = SubCategoryModel::where('category_id', 1)->where('active', 1)->paginate(20);
if ($subCategoryList->isNotEmpty()) {
$data["sub_category"] = $subCategoryList;
$data["count_article"] = [];
foreach ($subCategoryList as $subCate) {
$subCategoryId = $subCate->id;
$countSub = ArticleModel::where('active', 1)
->whereRaw('FIND_IN_SET(?, sub_category_ids)', [$subCategoryId])->count();
$data["count_article"][$subCategoryId] = $countSub;
}
}
$lang = 'category/index-en';
if (session()->get('locale') == 'th') {
$lang = 'category/index';
} else {
$lang = 'category/index-en';
}
return view($lang)
->with('itemView', $data);
}
public function article($subCateId, Request $request)
{
$subCategory = SubCategoryModel::where('id', $subCateId)->where('active', 1)->first();
if ($subCategory == null) {
return Redirect::to("category/chiangmai")
->withInput()
->with("messageFail", "Fail")
->with("messageDetail", 'Not found data');
}
// Get query parameters from the request
$keyword = $request->query('search');
$fromDate = $request->query('from');
$toDate = $request->query('to');
$fromDateFormatted = $fromDate ? date('Y-m-d', strtotime($fromDate)) . ' 00:00:00' : null;
$toDateFormatted = $toDate ? date('Y-m-d', strtotime($toDate)) . ' 23:59:59' : null;
// Apply filters only if they are provided
$query = ArticleModel::where('active', 1)
->where('category_id', 1)
->orderBy('id', 'DESC')
->whereRaw('FIND_IN_SET(?, sub_category_ids)', [$subCateId]);
if ($keyword) {
$query->where('name', 'like', "%{$keyword}%");
$query->orWhere('name_en', 'like', "%{$keyword}%");
}
if ($fromDateFormatted && $toDateFormatted) {
$query->whereBetween('due_date', [$fromDateFormatted, $toDateFormatted]);
}
$query->where('category_id', 1);
$data = $query->paginate(20);
$lang = 'category/article/index-en';
if (session()->get('locale') == 'th') {
$lang = 'category/article/index';
} else {
$lang = 'category/article/index-en';
}
return view($lang)
->with('subCategoryView', $subCategory)
->with('itemView', $data)
->with('fromDateView', $fromDate)
->with('toDateView', $toDate)
->with('keywordView', $keyword);
}
public function articleDetail($id)
{
// get by id
$data = ArticleModel::where('id', $id)->first();
$subCategories = SubCategoryModel::where('active', 1)->where('category_id', 1)->get();
$lang = 'category/article/detail-en';
if (session()->get('locale') == 'th') {
$lang = 'category/article/detail';
} else {
$lang = 'category/article/detail-en';
}
// get random
$randomArticles = ArticleModel::inRandomOrder()
->where('id', '!=', $id)
->limit(4)
->get();
return view($lang)
->with('itemView', $data)
->with('subCategoriesView', $subCategories)
->with('randomArticlesView', $randomArticles);
}
public function updateArticleCount(Request $request)
{
$id = $request->input('id');
// update count
$data = ArticleModel::where('id', $id)->first();
$count = $data->count_view ?? 0; // If null, set to 0
$dataUpdate = [
'count_view' => $count + 1, // Increment the count by 1
];
ArticleModel::where('id', $id)->update($dataUpdate);
return response()->json([
'status' => true,
'message' => "successfully"
]);
}
public function categoryWhereElse()
{
$data["sub_category"] = [];
$data["count_article"] = 0;
$subCategoryList = SubCategoryModel::where('category_id', 2)->where('active', 1)->paginate(20);
if ($subCategoryList->isNotEmpty()) {
$data["sub_category"] = $subCategoryList;
$data["count_article"] = [];
foreach ($subCategoryList as $subCate) {
$subCategoryId = $subCate->id;
$countSub = ArticleModel::where('active', 1)->whereRaw('FIND_IN_SET(?, sub_category_ids)', [$subCategoryId])->count();
$data["count_article"][$subCategoryId] = $countSub;
}
}
$lang = 'category-where-else/index-en';
if (session()->get('locale') == 'th') {
$lang = 'category-where-else/index';
} else {
$lang = 'category-where-else/index-en';
}
return view($lang)
->with('itemView', $data);
}
public function articleWhereElse($subCateId, Request $request)
{
$subCategory = SubCategoryModel::where('id', $subCateId)->where('active', 1)->first();
if ($subCategory == null) {
return Redirect::to("category/where-else")
->withInput()
->with("messageFail", "Fail")
->with("messageDetail", 'Not found data');
}
// Get query parameters from the request
$keyword = $request->query('search');
$fromDate = $request->query('from');
$toDate = $request->query('to');
$fromDateFormatted = $fromDate ? date('Y-m-d', strtotime($fromDate)) . ' 00:00:00' : null;
$toDateFormatted = $toDate ? date('Y-m-d', strtotime($toDate)) . ' 23:59:59' : null;
// Apply filters only if they are provided
$query = ArticleModel::where('active', 1)
->orderBy('id', 'DESC')
->whereRaw('FIND_IN_SET(?, sub_category_ids)', [$subCateId]);
if ($keyword) {
$query->where('name', 'like', "%{$keyword}%");
$query->orWhere('name_en', 'like', "%{$keyword}%");
}
if ($fromDateFormatted && $toDateFormatted) {
$query->whereBetween('due_date', [$fromDateFormatted, $toDateFormatted]);
}
$query->where('category_id', 2);
$data = $query->paginate(20);
$lang = 'category-where-else/article/index-en';
if (session()->get('locale') == 'th') {
$lang = 'category-where-else/article/index';
} else {
$lang = 'category-where-else/article/index-en';
}
return view($lang)
->with('subCategoryView', $subCategory)
->with('itemView', $data)
->with('fromDateView', $fromDate)
->with('toDateView', $toDate)
->with('keywordView', $keyword);
}
public function articleDetailWhereElse($id)
{
// get by id
$data = ArticleModel::where('id', $id)->first();
$subCategories = SubCategoryModel::where('active', 1)->where('category_id', 1)->get();
$lang = 'category-where-else/article/detail-en';
if (session()->get('locale') == 'th') {
$lang = 'category-where-else/article/detail';
} else {
$lang = 'category-where-else/article/detail-en';
}
// get random
$randomArticles = ArticleModel::inRandomOrder()
->where('id', '!=', $id)
->limit(4)
->get();
return view($lang)
->with('itemView', $data)
->with('subCategoriesView', $subCategories)
->with('randomArticlesView', $randomArticles);
}
public function contact()
{
$lang = 'contact/index-en';
if (session()->get('locale') == 'th') {
$lang = 'contact/index';
} else {
$lang = 'contact/index-en';
}
return view($lang);
}
public function articleAll(Request $request)
{
// Get query parameters from the request
$keyword = $request->query('search');
// Apply filters only if they are provided
$query = ArticleModel::where('active', 1)
->where('category_id', 1)
->orderBy('id', 'DESC');
if ($keyword) {
$query->where('name', 'like', "%{$keyword}%");
$query->orWhere('name_en', 'like', "%{$keyword}%");
}
$data = $query->paginate(20);
$lang = 'article/index-en';
if (session()->get('locale') == 'th') {
$lang = 'article/index';
} else {
$lang = 'article/index-en';
}
return view($lang)
->with('itemView', $data)
->with('keywordView', $keyword);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\LocaLocalization::class,
],
'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's middleware aliases.
*
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
*
* @var array<string, class-string|string>
*/
protected $middlewareAliases = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
protected function redirectTo(Request $request): ?string
{
return $request->expectsJson() ? null : route('login');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;
class Language
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
*
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, \Closure $next)
{
if (Session::get('locale')) {
App::setLocale(Session::get('locale'));
}
return $next($request);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;
class LocaLocalization
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
*
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, \Closure $next)
{
if (Session::get('locale')) {
App::setLocale(Session::get('locale'));
}
return $next($request);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Middleware;
use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next, string ...$guards): Response
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array<int, string>
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustHosts as Middleware;
class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array<int, string|null>
*/
public function hosts(): array
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array<int, string>|string|null
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
class ValidateSignature extends Middleware
{
/**
* The names of the query string parameters that should be ignored.
*
* @var array<int, string>
*/
protected $except = [
// 'fbclid',
// 'utm_campaign',
// 'utm_content',
// 'utm_medium',
// 'utm_source',
// 'utm_term',
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array<int, string>
*/
protected $except = [
//
];
}